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,41 @@ 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+ /// (which is a [CupertinoDialogAction] for OS platforms).
13+ ///
1014/// Dismiss the dialog by calling `tester.tap(find.byWidget(okButton))` .
1115Widget checkErrorDialog (WidgetTester tester, {
1216 required String expectedTitle,
1317 String ? expectedMessage,
1418}) {
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+ if (defaultTargetPlatform == TargetPlatform .iOS
20+ || defaultTargetPlatform == TargetPlatform .macOS) {
21+
22+ final dialog = tester.widget <CupertinoAlertDialog >(find.byType (CupertinoAlertDialog ));
23+
1924 tester.widget (find.descendant (matchRoot: true ,
20- of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
21- }
25+ of: find.byWidget (dialog.title! ), matching: find.text (expectedTitle)));
2226
23- return tester.widget (
24- find.descendant (of: find.byWidget (dialog),
25- matching: find.widgetWithText (TextButton , 'OK' )));
27+ if (expectedMessage != null ) {
28+ tester.widget (find.descendant (matchRoot: true ,
29+ of: find.byWidget (dialog.content! ), matching: find.text (expectedMessage)));
30+ }
31+
32+ return tester.widget (
33+ find.descendant (of: find.byWidget (dialog),
34+ matching: find.widgetWithText (CupertinoDialogAction , 'OK' )));
35+
36+ }
37+ else {
38+ final dialog = tester.widget <Dialog >(find.byType (Dialog ));
39+ tester.widget (find.widgetWithText (Dialog , expectedTitle));
40+ if (expectedMessage != null ) {
41+ tester.widget (find.widgetWithText (Dialog , expectedMessage));
42+ }
43+ return tester.widget (
44+ find.descendant (of: find.byWidget (dialog),
45+ matching: find.widgetWithText (TextButton , 'OK' )));
46+ }
47+
2648}
0 commit comments