diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index d34a0a31e9..98bc2e20be 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -1039,6 +1039,7 @@ class _ActionButtonParentData extends MultiChildLayoutParentData { class CupertinoDialogAction extends StatelessWidget { /// Creates an action for an iOS-style dialog. const CupertinoDialogAction({ + Key key, this.onPressed, this.isDefaultAction = false, this.isDestructiveAction = false, @@ -1046,7 +1047,8 @@ class CupertinoDialogAction extends StatelessWidget { @required this.child, }) : assert(child != null), assert(isDefaultAction != null), - assert(isDestructiveAction != null); + assert(isDestructiveAction != null), + super(key: key); /// The callback that is called when the button is tapped or otherwise /// activated. diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index 541b1c692c..973c208fa7 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -1023,6 +1023,36 @@ void main() { transition = tester.widgetList(find.byType(FadeTransition)).elementAt(1); expect(transition.opacity.value, closeTo(0.0, 0.001)); }); + + testWidgets('Actions are accessible by key', (WidgetTester tester) async { + await tester.pumpWidget( + createAppWithButtonThatLaunchesDialog( + dialogBuilder: (BuildContext context) { + return const CupertinoAlertDialog( + title: Text('The Title'), + content: Text('The message'), + actions: [ + CupertinoDialogAction( + key: Key('option_1'), + child: Text('Option 1'), + ), + CupertinoDialogAction( + key: Key('option_2'), + child: Text('Option 2'), + ), + ], + ); + }, + ), + ); + + await tester.tap(find.text('Go')); + await tester.pump(); + + expect(find.byKey(const Key('option_1')), findsOneWidget); + expect(find.byKey(const Key('option_2')), findsOneWidget); + expect(find.byKey(const Key('option_3')), findsNothing); + }); } RenderBox findActionButtonRenderBoxByTitle(WidgetTester tester, String title) {