-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ResultBanner extends StatefulWidget { | ||
const ResultBanner({Key key}) : super(key: key); | ||
@override | ||
ResultBannerState createState() => ResultBannerState(); | ||
} | ||
|
||
class ResultBannerState extends State<ResultBanner> { | ||
var _text = ''; | ||
|
||
void updateText(String text) { | ||
setState(() { | ||
_text = text; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialBanner( | ||
content: Text('Result: $_text'), | ||
actions: <Widget>[ | ||
FlatButton( | ||
child: Text('Clear'), | ||
onPressed: () => updateText(''), | ||
) | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This is a basic Flutter widget test. | ||
// | ||
// To perform an interaction with a widget in your test, use the WidgetTester | ||
// utility that Flutter provides. For example, you can send tap and scroll | ||
// gestures. You can also use WidgetTester to find child widgets in the widget | ||
// tree, read text, and verify that the values of widget properties are correct. | ||
|
||
import 'package:example/app.dart'; | ||
import 'package:example/router.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
void main() { | ||
testWidgets('OK Dialog', (tester) async { | ||
await _setupTester(tester); | ||
|
||
await tester.tap(find.widgetWithText(ListTile, 'OK Dialog')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Title'), findsOneWidget); | ||
expect(find.text('This is message.'), findsOneWidget); | ||
await tester.tap(find.widgetWithText(FlatButton, 'OK')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Result: OkCancelResult.ok'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('OK Dialog (barrierDismissible: false)', (tester) async { | ||
await _setupTester(tester); | ||
|
||
await tester.tap( | ||
find.widgetWithText(ListTile, 'OK Dialog (barrierDismissible: false)')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Title'), findsOneWidget); | ||
expect(find.text('This is message.'), findsOneWidget); | ||
await tester.tap(find.widgetWithText(FlatButton, 'OK')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Result: OkCancelResult.ok'), findsOneWidget); | ||
}); | ||
} | ||
|
||
Future<void> _setupTester(WidgetTester tester) async { | ||
await tester.pumpWidget(MultiProvider( | ||
providers: [ | ||
Provider(create: (context) => Router()), | ||
], | ||
child: const App(), | ||
)); | ||
|
||
await tester.tap(find.widgetWithText(ListTile, 'Alert')); | ||
await tester.pumpAndSettle(); | ||
} |