1
+ import 'package:flutter/cupertino.dart' ;
2
+ import 'package:flutter/foundation.dart' ;
1
3
import 'package:flutter/material.dart' ;
2
4
import 'package:flutter_test/flutter_test.dart' ;
3
5
@@ -6,21 +8,40 @@ import 'package:flutter_test/flutter_test.dart';
6
8
/// Checks for an error dialog matching an expected title
7
9
/// and, optionally, matching an expected message. Fails if none is found.
8
10
///
9
- /// On success, returns the widget's "OK" button.
11
+ /// On success, returns the widget's "OK" button
12
+ ///
10
13
/// Dismiss the dialog by calling `tester.tap(find.byWidget(okButton))` .
11
14
Widget checkErrorDialog (WidgetTester tester, {
12
15
required String expectedTitle,
13
16
String ? expectedMessage,
14
17
}) {
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)));
18
+ switch (defaultTargetPlatform) {
19
+ case TargetPlatform .android:
20
+ case TargetPlatform .fuchsia:
21
+ case TargetPlatform .linux:
22
+ case TargetPlatform .windows: {
23
+ final dialog = tester.widget <Dialog >(find.byType (Dialog ));
24
+ tester.widget (find.widgetWithText (Dialog , expectedTitle));
25
+ if (expectedMessage != null ) {
26
+ tester.widget (find.widgetWithText (Dialog , expectedMessage));
27
+ }
28
+ return tester.widget (
29
+ find.descendant (of: find.byWidget (dialog),
30
+ matching: find.widgetWithText (TextButton , 'OK' )));
31
+ }
32
+ case TargetPlatform .iOS:
33
+ case TargetPlatform .macOS: {
34
+ final dialog = tester.widget <CupertinoAlertDialog >(
35
+ find.byType (CupertinoAlertDialog ));
36
+ tester.widget (find.descendant (matchRoot: true ,
37
+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
38
+ if (expectedMessage != null ) {
39
+ tester.widget (find.descendant (matchRoot: true ,
40
+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
41
+ }
42
+ return tester.widget (find.descendant (of: find.byWidget (dialog),
43
+ matching: find.widgetWithText (CupertinoDialogAction , 'OK' )));
44
+ }
21
45
}
22
-
23
- return tester.widget (
24
- find.descendant (of: find.byWidget (dialog),
25
- matching: find.widgetWithText (TextButton , 'OK' )));
46
+
26
47
}
0 commit comments