diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index b11b8eea31..4fda6c2e3b 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -1043,7 +1043,9 @@ class CupertinoDialogAction extends StatelessWidget { this.isDestructiveAction = false, this.textStyle, @required this.child, - }) : assert(child != null); + }) : assert(child != null), + assert(isDefaultAction != null), + assert(isDestructiveAction != null); /// The callback that is called when the button is tapped or otherwise /// activated. @@ -1054,11 +1056,15 @@ class CupertinoDialogAction extends StatelessWidget { /// Set to true if button is the default choice in the dialog. /// /// Default buttons are bold. + /// + /// This parameters defaults to false and cannot be null. final bool isDefaultAction; /// Whether this action destroys an object. /// /// For example, an action that deletes an email is destructive. + /// + /// Defaults to false and cannot be null. final bool isDestructiveAction; /// [TextStyle] to apply to any text that appears in this button. @@ -1149,6 +1155,10 @@ class CupertinoDialogAction extends StatelessWidget { TextStyle style = _kCupertinoDialogActionStyle; style = style.merge(textStyle); + if (isDefaultAction) { + style = style.copyWith(fontWeight: FontWeight.w600); + } + if (isDestructiveAction) { style = style.copyWith(color: CupertinoColors.destructiveRed); } diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index bb414b851c..6a59aac101 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -52,7 +52,7 @@ void main() { expect(find.text('Delete'), findsNothing); }); - testWidgets('Dialog destructive action styles', (WidgetTester tester) async { + testWidgets('Dialog destructive action style', (WidgetTester tester) async { await tester.pumpWidget(boilerplate(const CupertinoDialogAction( isDestructiveAction: true, child: Text('Ok'), @@ -60,8 +60,7 @@ void main() { final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); - expect(widget.style.color.red, greaterThan(widget.style.color.blue)); - expect(widget.style.color.alpha, lessThan(255)); + expect(widget.style.color.withAlpha(255), CupertinoColors.destructiveRed); }); testWidgets('Has semantic annotations', (WidgetTester tester) async { @@ -132,7 +131,7 @@ void main() { semantics.dispose(); }); - testWidgets('Dialog default action styles', (WidgetTester tester) async { + testWidgets('Dialog default action style', (WidgetTester tester) async { await tester.pumpWidget(boilerplate(const CupertinoDialogAction( isDefaultAction: true, child: Text('Ok'), @@ -140,10 +139,10 @@ void main() { final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); - expect(widget.style.fontWeight, equals(FontWeight.w400)); + expect(widget.style.fontWeight, equals(FontWeight.w600)); }); - testWidgets('Default and destructive style', (WidgetTester tester) async { + testWidgets('Dialog default and destructive action styles', (WidgetTester tester) async { await tester.pumpWidget(boilerplate(const CupertinoDialogAction( isDefaultAction: true, isDestructiveAction: true, @@ -152,8 +151,30 @@ void main() { final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); - expect(widget.style.fontWeight, equals(FontWeight.w400)); - expect(widget.style.color.red, greaterThan(widget.style.color.blue)); + expect(widget.style.color.withAlpha(255), CupertinoColors.destructiveRed); + expect(widget.style.fontWeight, equals(FontWeight.w600)); + }); + + testWidgets('Dialog disabled action style', (WidgetTester tester) async { + await tester.pumpWidget(boilerplate(const CupertinoDialogAction( + child: Text('Ok'), + ))); + + final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); + + expect(widget.style.color.opacity, greaterThanOrEqualTo(127 / 255)); + expect(widget.style.color.opacity, lessThanOrEqualTo(128 / 255)); + }); + + testWidgets('Dialog enabled action style', (WidgetTester tester) async { + await tester.pumpWidget(boilerplate(CupertinoDialogAction( + child: const Text('Ok'), + onPressed: () {}, + ))); + + final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); + + expect(widget.style.color.opacity, equals(1.0)); }); testWidgets('Message is scrollable, has correct padding with large text sizes', (WidgetTester tester) async {