@@ -1155,6 +1155,52 @@ void main() {
1155
1155
expect (pressed, null );
1156
1156
});
1157
1157
1158
+ testWidgets ('Taps on legacy button calls onPressed and renders correctly' , (WidgetTester tester) async {
1159
+ // Legacy buttons are implemented with [GestureDetector.onTap]. Apps that
1160
+ // use customized legacy buttons should continue to work.
1161
+ //
1162
+ // Regression test for https://github.com/flutter/flutter/issues/150980 .
1163
+ bool wasPressed = false ;
1164
+ await tester.pumpWidget (
1165
+ createAppWithButtonThatLaunchesActionSheet (
1166
+ Builder (builder: (BuildContext context) {
1167
+ return CupertinoActionSheet (
1168
+ actions: < Widget > [
1169
+ LegacyAction (
1170
+ child: const Text ('Legacy' ),
1171
+ onPressed: () {
1172
+ expect (wasPressed, false );
1173
+ wasPressed = true ;
1174
+ Navigator .pop (context);
1175
+ },
1176
+ ),
1177
+ CupertinoActionSheetAction (child: const Text ('One' ), onPressed: () {}),
1178
+ CupertinoActionSheetAction (child: const Text ('Two' ), onPressed: () {}),
1179
+ ],
1180
+ );
1181
+ }),
1182
+ ),
1183
+ );
1184
+
1185
+ await tester.tap (find.text ('Go' ));
1186
+ await tester.pumpAndSettle ();
1187
+ expect (wasPressed, isFalse);
1188
+
1189
+ // Push the legacy button and hold for a while to activate the pressing effect.
1190
+ final TestGesture gesture = await tester.startGesture (tester.getCenter (find.text ('Legacy' )));
1191
+ await tester.pump (const Duration (seconds: 1 ));
1192
+ expect (wasPressed, isFalse);
1193
+ await expectLater (
1194
+ find.byType (CupertinoActionSheet ),
1195
+ matchesGoldenFile ('cupertinoActionSheet.legacyButton.png' ),
1196
+ );
1197
+
1198
+ await gesture.up ();
1199
+ await tester.pumpAndSettle ();
1200
+ expect (wasPressed, isTrue);
1201
+ expect (find.text ('Legacy' ), findsNothing);
1202
+ });
1203
+
1158
1204
testWidgets ('Action sheet width is correct when given infinite horizontal space' , (WidgetTester tester) async {
1159
1205
await tester.pumpWidget (
1160
1206
createAppWithButtonThatLaunchesActionSheet (
@@ -2054,3 +2100,32 @@ class OverrideMediaQuery extends StatelessWidget {
2054
2100
);
2055
2101
}
2056
2102
}
2103
+
2104
+ // Old-style action sheet buttons, which are implemented with
2105
+ // `GestureDetector.onTap`.
2106
+ class LegacyAction extends StatelessWidget {
2107
+ const LegacyAction ({
2108
+ super .key,
2109
+ required this .onPressed,
2110
+ required this .child,
2111
+ });
2112
+
2113
+ final VoidCallback onPressed;
2114
+ final Widget child;
2115
+
2116
+ @override
2117
+ Widget build (BuildContext context) {
2118
+ return GestureDetector (
2119
+ onTap: onPressed,
2120
+ behavior: HitTestBehavior .opaque,
2121
+ child: ConstrainedBox (
2122
+ constraints: const BoxConstraints (minHeight: 57 ),
2123
+ child: Container (
2124
+ alignment: AlignmentDirectional .center,
2125
+ padding: const EdgeInsets .symmetric (vertical: 16.0 , horizontal: 10.0 ),
2126
+ child: child,
2127
+ ),
2128
+ ),
2129
+ );
2130
+ }
2131
+ }
0 commit comments