1+ import 'package:flutter/cupertino.dart' ;
2+ import 'package:flutter/foundation.dart' ;
13import 'package:flutter/material.dart' ;
24import 'package:flutter_test/flutter_test.dart' ;
35
@@ -6,21 +8,40 @@ import 'package:flutter_test/flutter_test.dart';
68/// Checks for an error dialog matching an expected title
79/// and, optionally, matching an expected message. Fails if none is found.
810///
9- /// On success, returns the widget's "OK" button.
11+ /// On success, returns the widget's "OK" button
12+ ///
1013/// Dismiss the dialog by calling `tester.tap(find.byWidget(okButton))` .
1114Widget checkErrorDialog (WidgetTester tester, {
1215 required String expectedTitle,
1316 String ? expectedMessage,
1417}) {
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+ }
2145 }
22-
23- return tester.widget (
24- find.descendant (of: find.byWidget (dialog),
25- matching: find.widgetWithText (TextButton , 'OK' )));
46+
2647}
0 commit comments