@@ -19,6 +19,69 @@ import 'package:flutter_test/flutter_test.dart';
19
19
import '../widgets/semantics_tester.dart' ;
20
20
21
21
void main () {
22
+ testWidgets ('Overall appearance is correct for the light theme' , (WidgetTester tester) async {
23
+ await tester.pumpWidget (
24
+ TestScaffoldApp (
25
+ theme: const CupertinoThemeData (brightness: Brightness .light),
26
+ dialog: CupertinoAlertDialog (
27
+ content: const Text ('The content' ),
28
+ actions: < Widget > [
29
+ CupertinoDialogAction (child: const Text ('One' ), onPressed: () {}),
30
+ CupertinoDialogAction (child: const Text ('Two' ), onPressed: () {}),
31
+ ],
32
+ ),
33
+ ),
34
+ );
35
+
36
+ await tester.tap (find.text ('Go' ));
37
+ await tester.pumpAndSettle ();
38
+
39
+ final TestGesture gesture = await tester.startGesture (tester.getCenter (find.text ('One' )));
40
+ await tester.pumpAndSettle ();
41
+ // This golden file also verifies the structure of an alert dialog that
42
+ // has a content, no title, and no overscroll for any sections (in contrast
43
+ // to cupertinoAlertDialog.dark-theme.png).
44
+ await expectLater (
45
+ find.byType (CupertinoApp ),
46
+ matchesGoldenFile ('cupertinoAlertDialog.overall-light-theme.png' ),
47
+ );
48
+
49
+ await gesture.up ();
50
+ });
51
+
52
+ testWidgets ('Overall appearance is correct for the dark theme' , (WidgetTester tester) async {
53
+ await tester.pumpWidget (
54
+ TestScaffoldApp (
55
+ theme: const CupertinoThemeData (brightness: Brightness .dark),
56
+ dialog: CupertinoAlertDialog (
57
+ title: const Text ('The title' ),
58
+ content: const Text ('The content' ),
59
+ actions: List <Widget >.generate (20 , (int i) =>
60
+ CupertinoDialogAction (
61
+ onPressed: () {},
62
+ child: Text ('Button $i ' ),
63
+ ),
64
+ ),
65
+ ),
66
+ ),
67
+ );
68
+
69
+ await tester.tap (find.text ('Go' ));
70
+ await tester.pumpAndSettle ();
71
+
72
+ final TestGesture gesture = await tester.startGesture (tester.getCenter (find.text ('Button 0' )));
73
+ await tester.pumpAndSettle ();
74
+ // This golden file also verifies the structure of an action sheet that
75
+ // has both a message and a title, and an overscrolled action section (in
76
+ // contrast to cupertinoAlertDialog.light-theme.png).
77
+ await expectLater (
78
+ find.byType (CupertinoApp ),
79
+ matchesGoldenFile ('cupertinoAlertDialog.overall-dark-theme.png' ),
80
+ );
81
+
82
+ await gesture.up ();
83
+ });
84
+
22
85
testWidgets ('Alert dialog control test' , (WidgetTester tester) async {
23
86
bool didDelete = false ;
24
87
@@ -181,16 +244,16 @@ void main() {
181
244
182
245
testWidgets ('Has semantic annotations' , (WidgetTester tester) async {
183
246
final SemanticsTester semantics = SemanticsTester (tester);
184
- await tester.pumpWidget (const MaterialApp (home : Material (
185
- child : CupertinoAlertDialog (
247
+ await tester.pumpWidget (const CupertinoApp (
248
+ home : CupertinoAlertDialog (
186
249
title: Text ('The Title' ),
187
250
content: Text ('Content' ),
188
251
actions: < Widget > [
189
252
CupertinoDialogAction (child: Text ('Cancel' )),
190
253
CupertinoDialogAction (child: Text ('OK' )),
191
254
],
192
255
),
193
- ))) ;
256
+ ));
194
257
195
258
expect (
196
259
semantics,
@@ -506,7 +569,7 @@ void main() {
506
569
507
570
// Check that the title/message section is not displayed
508
571
expect (actionScrollController.offset, 0.0 );
509
- expect (tester.getTopLeft (find.widgetWithText (CupertinoDialogAction , 'One' )).dy, equals (277.5 ));
572
+ expect (tester.getTopLeft (find.widgetWithText (CupertinoDialogAction , 'One' )).dy, equals (270.75 ));
510
573
511
574
// Check that the button's vertical size is the same.
512
575
expect (
@@ -1160,7 +1223,7 @@ void main() {
1160
1223
1161
1224
testWidgets ('Dialog widget insets by MediaQuery viewInsets' , (WidgetTester tester) async {
1162
1225
await tester.pumpWidget (
1163
- const MaterialApp (
1226
+ const CupertinoApp (
1164
1227
home: MediaQuery (
1165
1228
data: MediaQueryData (),
1166
1229
child: CupertinoAlertDialog (content: Placeholder (fallbackHeight: 200.0 )),
@@ -1171,7 +1234,7 @@ void main() {
1171
1234
final Rect placeholderRectWithoutInsets = tester.getRect (find.byType (Placeholder ));
1172
1235
1173
1236
await tester.pumpWidget (
1174
- const MaterialApp (
1237
+ const CupertinoApp (
1175
1238
home: MediaQuery (
1176
1239
data: MediaQueryData (viewInsets: EdgeInsets .fromLTRB (40.0 , 30.0 , 20.0 , 10.0 )),
1177
1240
child: CupertinoAlertDialog (content: Placeholder (fallbackHeight: 200.0 )),
@@ -1188,70 +1251,6 @@ void main() {
1188
1251
expect (tester.getRect (find.byType (Placeholder )), placeholderRectWithoutInsets.translate (10 , 10 ));
1189
1252
});
1190
1253
1191
- testWidgets ('Material2 - Default cupertino dialog golden' , (WidgetTester tester) async {
1192
- await tester.pumpWidget (
1193
- createAppWithButtonThatLaunchesDialog (
1194
- useMaterial3: false ,
1195
- dialogBuilder: (BuildContext context) {
1196
- return MediaQuery .withClampedTextScaling (
1197
- minScaleFactor: 3.0 ,
1198
- maxScaleFactor: 3.0 ,
1199
- child: const RepaintBoundary (
1200
- child: CupertinoAlertDialog (
1201
- title: Text ('Title' ),
1202
- content: Text ('text' ),
1203
- actions: < Widget > [
1204
- CupertinoDialogAction (child: Text ('No' )),
1205
- CupertinoDialogAction (child: Text ('OK' )),
1206
- ],
1207
- ),
1208
- ),
1209
- );
1210
- },
1211
- ),
1212
- );
1213
-
1214
- await tester.tap (find.text ('Go' ));
1215
- await tester.pumpAndSettle ();
1216
-
1217
- await expectLater (
1218
- find.byType (CupertinoAlertDialog ),
1219
- matchesGoldenFile ('m2_dialog_test.cupertino.default.png' ),
1220
- );
1221
- });
1222
-
1223
- testWidgets ('Material3 - Default cupertino dialog golden' , (WidgetTester tester) async {
1224
- await tester.pumpWidget (
1225
- createAppWithButtonThatLaunchesDialog (
1226
- useMaterial3: true ,
1227
- dialogBuilder: (BuildContext context) {
1228
- return MediaQuery .withClampedTextScaling (
1229
- minScaleFactor: 3.0 ,
1230
- maxScaleFactor: 3.0 ,
1231
- child: const RepaintBoundary (
1232
- child: CupertinoAlertDialog (
1233
- title: Text ('Title' ),
1234
- content: Text ('text' ),
1235
- actions: < Widget > [
1236
- CupertinoDialogAction (child: Text ('No' )),
1237
- CupertinoDialogAction (child: Text ('OK' )),
1238
- ],
1239
- ),
1240
- ),
1241
- );
1242
- },
1243
- ),
1244
- );
1245
-
1246
- await tester.tap (find.text ('Go' ));
1247
- await tester.pumpAndSettle ();
1248
-
1249
- await expectLater (
1250
- find.byType (CupertinoAlertDialog ),
1251
- matchesGoldenFile ('m3_dialog_test.cupertino.default.png' ),
1252
- );
1253
- });
1254
-
1255
1254
testWidgets ('showCupertinoDialog - custom barrierLabel' , (WidgetTester tester) async {
1256
1255
final SemanticsTester semantics = SemanticsTester (tester);
1257
1256
@@ -1363,7 +1362,7 @@ void main() {
1363
1362
testWidgets ('CupertinoAlertDialog scrollbars controllers should be different' , (WidgetTester tester) async {
1364
1363
// https://github.com/flutter/flutter/pull/81278
1365
1364
await tester.pumpWidget (
1366
- const MaterialApp (
1365
+ const CupertinoApp (
1367
1366
home: MediaQuery (
1368
1367
data: MediaQueryData (),
1369
1368
child: CupertinoAlertDialog (
@@ -1565,24 +1564,20 @@ RenderBox findScrollableActionsSectionRenderBox(WidgetTester tester) {
1565
1564
1566
1565
Widget createAppWithButtonThatLaunchesDialog ({
1567
1566
required WidgetBuilder dialogBuilder,
1568
- bool ? useMaterial3,
1569
1567
}) {
1570
- return MaterialApp (
1571
- theme: ThemeData (useMaterial3: useMaterial3),
1572
- home: Material (
1573
- child: Center (
1574
- child: Builder (builder: (BuildContext context) {
1575
- return ElevatedButton (
1576
- onPressed: () {
1577
- showDialog <void >(
1578
- context: context,
1579
- builder: dialogBuilder,
1580
- );
1581
- },
1582
- child: const Text ('Go' ),
1583
- );
1584
- }),
1585
- ),
1568
+ return CupertinoApp (
1569
+ home: Center (
1570
+ child: Builder (builder: (BuildContext context) {
1571
+ return CupertinoButton (
1572
+ onPressed: () {
1573
+ showCupertinoDialog <void >(
1574
+ context: context,
1575
+ builder: dialogBuilder,
1576
+ );
1577
+ },
1578
+ child: const Text ('Go' ),
1579
+ );
1580
+ }),
1586
1581
),
1587
1582
);
1588
1583
}
@@ -1595,13 +1590,11 @@ Widget boilerplate(Widget child) {
1595
1590
}
1596
1591
1597
1592
Widget createAppWithCenteredButton (Widget child) {
1598
- return MaterialApp (
1599
- home: Material (
1600
- child: Center (
1601
- child: ElevatedButton (
1602
- onPressed: null ,
1603
- child: child,
1604
- ),
1593
+ return CupertinoApp (
1594
+ home: Center (
1595
+ child: CupertinoButton (
1596
+ onPressed: null ,
1597
+ child: child,
1605
1598
),
1606
1599
),
1607
1600
);
@@ -1643,3 +1636,52 @@ class _RestorableDialogTestWidget extends StatelessWidget {
1643
1636
);
1644
1637
}
1645
1638
}
1639
+
1640
+ // Shows an app that has a button with text "Go", and clicking this button
1641
+ // displays the `dialog` and hides the button.
1642
+ //
1643
+ // The `theme` will be applied to the app and determines the background.
1644
+ class TestScaffoldApp extends StatefulWidget {
1645
+ const TestScaffoldApp ({super .key, required this .theme, required this .dialog});
1646
+ final CupertinoThemeData theme;
1647
+ final Widget dialog;
1648
+
1649
+ @override
1650
+ TestScaffoldAppState createState () => TestScaffoldAppState ();
1651
+ }
1652
+
1653
+ class TestScaffoldAppState extends State <TestScaffoldApp > {
1654
+ bool _pressedButton = false ;
1655
+
1656
+ @override
1657
+ Widget build (BuildContext context) {
1658
+ return CupertinoApp (
1659
+ // Hide the debug banner. Because this CupertinoApp is captured in golden
1660
+ // test as a whole. The debug banner contains tilted text, whose
1661
+ // anti-alias might cause false negative result.
1662
+ // https://github.com/flutter/flutter/pull/150442
1663
+ debugShowCheckedModeBanner: false ,
1664
+ theme: widget.theme,
1665
+ home: Builder (builder: (BuildContext context) =>
1666
+ CupertinoPageScaffold (
1667
+ child: Center (
1668
+ child: _pressedButton ? Container () : CupertinoButton (
1669
+ onPressed: () {
1670
+ setState (() {
1671
+ _pressedButton = true ;
1672
+ });
1673
+ showCupertinoDialog <void >(
1674
+ context: context,
1675
+ builder: (BuildContext context) {
1676
+ return widget.dialog;
1677
+ },
1678
+ );
1679
+ },
1680
+ child: const Text ('Go' ),
1681
+ ),
1682
+ ),
1683
+ ),
1684
+ ),
1685
+ );
1686
+ }
1687
+ }
0 commit comments