File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_test/flutter_test.dart' ;
3
+
4
+ /// In a widget test, check that showErrorDialog was called with the right text.
5
+ ///
6
+ /// Checks for an error dialog matching an expected title
7
+ /// and, optionally, matching an expected message. Fails if none is found.
8
+ ///
9
+ /// On success, returns the widget's "OK" button.
10
+ /// Dismiss the dialog by calling `tester.tap(find.byWidget(okButton))` .
11
+ Widget checkErrorDialog (WidgetTester tester, {
12
+ required String expectedTitle,
13
+ String ? expectedMessage,
14
+ }) {
15
+ final dialog = tester.widget <AlertDialog >(find.byType (AlertDialog ));
16
+ tester.widget (find.descendant (matchRoot: true ,
17
+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
18
+ if (expectedMessage != null ) {
19
+ tester.widget (find.descendant (matchRoot: true ,
20
+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
21
+ }
22
+
23
+ return tester.widget (
24
+ find.descendant (of: find.byWidget (dialog),
25
+ matching: find.widgetWithText (TextButton , 'OK' )));
26
+ }
You can’t perform that action at this time.
0 commit comments