maestro_test 0.2.0 maestro_test: ^0.2.0 copied to clipboard
Simple, easy-to-learn, Flutter-native UI testing framework eliminating limitations of flutter_driver
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.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;
final _notificationsPlugin = FlutterLocalNotificationsPlugin();
@override
void initState() {
super.initState();
_notificationsPlugin.initialize(
const InitializationSettings(
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
),
onDidReceiveNotificationResponse: (notificationResponse) {
print('tapped notification with ID ${notificationResponse.id}');
},
);
}
void _incrementCounter() {
setState(() {
_counter++;
});
}
void _showNotification({required int id}) {
_notificationsPlugin.show(
id,
'Maestro example',
'Hello there! This notification has ID=$id',
const NotificationDetails(
android: AndroidNotificationDetails(
'main',
'Default notification channel',
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
key: const ValueKey('counterText'),
style: Theme.of(context).textTheme.headline4,
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
TextButton(
onPressed: () => _showNotification(id: 1),
child: const Text('Show notification with ID=1'),
),
TextButton(
onPressed: () => _showNotification(id: 2),
child: const Text('Show notification with ID=2'),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}