maestro_test 0.4.1 maestro_test: ^0.4.1 copied to clipboard
Simple, easy-to-learn, and powerful Flutter-native UI testing framework eliminating limitations of flutter_test and flutter_driver
import 'package:example/loading_screen.dart';
import 'package:example/notifications_screen.dart';
import 'package:example/overlay_screen.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _counter = 0;
void _incrementCounter([int value = 1]) {
final newValue = _counter + value;
print('incrementing counter by $value (to $newValue)');
setState(() {
_counter = newValue;
});
}
void _decrementCounter([int value = 1]) {
final newValue = _counter - value;
print('decrementing counter by $value (to $newValue)');
setState(() {
_counter = newValue;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: const Key('scaffold'),
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
key: const Key('counterText'),
style: Theme.of(context).textTheme.headline4,
),
Container(
key: const Key('box1'),
color: Colors.grey,
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('box 1'),
ListTile(
onTap: () => _incrementCounter(10),
key: const Key('tile1'),
title: const Text('Add'),
trailing: IconButton(
icon: const Icon(Icons.add, key: Key('icon1')),
onPressed: _incrementCounter,
),
),
ListTile(
onTap: () => _decrementCounter(10),
key: const Key('tile2'),
title: const Text('Subtract'),
trailing: IconButton(
icon: const Icon(Icons.remove, key: Key('icon2')),
onPressed: _decrementCounter,
),
),
],
),
),
const SizedBox(height: 16),
Container(
key: const Key('box2'),
color: Colors.grey,
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('box 2'),
ListTile(
onTap: () => _incrementCounter(10),
key: const Key('tile1'),
title: const Text('Add'),
trailing: IconButton(
icon: const Icon(Icons.add, key: Key('icon1')),
onPressed: _incrementCounter,
),
),
ListTile(
onTap: () => _decrementCounter(10),
key: const Key('tile2'),
title: const Text('Subtract'),
trailing: IconButton(
icon: const Icon(Icons.remove, key: Key('icon2')),
onPressed: _decrementCounter,
),
),
],
),
),
TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const LoadingScreen(),
),
),
child: const Text('Open loading screen'),
),
TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const NotificationsScreen(),
),
),
child: const Text('Open notifications screen'),
),
TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const OverlayScreen(),
),
),
child: const Text('Open overlay screen'),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}