From 81ec553fb6234f48da584400253eab827755721f Mon Sep 17 00:00:00 2001 From: xster Date: Wed, 10 May 2017 18:59:50 -0700 Subject: [PATCH] More Cupertino dialog UI tweaks (#9960) * is default * hit target * correct test name * review note --- .../demo/cupertino/cupertino_dialog_demo.dart | 5 ++-- .../flutter/lib/src/cupertino/dialog.dart | 16 ++++++++-- .../flutter/test/cupertino/dialog_test.dart | 30 +++++++++++++++++-- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_dialog_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_dialog_demo.dart index f721f50236..cadff8aafd 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_dialog_demo.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_dialog_demo.dart @@ -53,11 +53,12 @@ class _CupertinoDialogDemoState extends State { actions: [ new CupertinoDialogAction( child: const Text('Discard'), - isDestructive: true, + isDestructiveAction: true, onPressed: () { Navigator.pop(context, 'Discard'); } ), new CupertinoDialogAction( - child: const Text('Cancel', style: const TextStyle(fontWeight: FontWeight.w600)), + child: const Text('Cancel'), + isDefaultAction: true, onPressed: () { Navigator.pop(context, 'Cancel'); } ), ] diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index 3344c70a95..dd2b61b065 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -191,7 +191,8 @@ class CupertinoDialogAction extends StatelessWidget { /// Creates an action for an iOS-style dialog. const CupertinoDialogAction({ this.onPressed, - this.isDestructive: false, + this.isDefaultAction: false, + this.isDestructiveAction: false, @required this.child, }) : assert(child != null); @@ -200,10 +201,15 @@ class CupertinoDialogAction extends StatelessWidget { /// If this is set to null, the button will be disabled. final VoidCallback onPressed; + /// Set to true if button is the default choice in the dialog. + /// + /// Default buttons are bolded. + final bool isDefaultAction; + /// Whether this action destroys an object. /// /// For example, an action that deletes an email is destructive. - final bool isDestructive; + final bool isDestructiveAction; /// The widget below this widget in the tree. /// @@ -218,7 +224,10 @@ class CupertinoDialogAction extends StatelessWidget { Widget build(BuildContext context) { TextStyle style = _kCupertinoDialogActionStyle; - if (isDestructive) + if (isDefaultAction) + style = style.copyWith(fontWeight: FontWeight.w600); + + if (isDestructiveAction) style = style.copyWith(color: _kDestructiveActionColor); if (!enabled) @@ -226,6 +235,7 @@ class CupertinoDialogAction extends StatelessWidget { return new GestureDetector( onTap: onPressed, + behavior: HitTestBehavior.opaque, child: new Center( child: new DefaultTextStyle( style: style, diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index 2f7b0fc395..4cfa288c02 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -27,7 +27,7 @@ void main() { child: const Text('Cancel'), ), new CupertinoDialogAction( - isDestructive: true, + isDestructiveAction: true, onPressed: () { didDelete = true; Navigator.pop(context); @@ -63,9 +63,9 @@ void main() { expect(find.text('Delete'), findsNothing); }); - testWidgets('Dialog action styles', (WidgetTester tester) async { + testWidgets('Dialog destructive action styles', (WidgetTester tester) async { await tester.pumpWidget(const CupertinoDialogAction( - isDestructive: true, + isDestructiveAction: true, child: const Text('Ok'), )); @@ -74,4 +74,28 @@ void main() { expect(widget.style.color.red, greaterThan(widget.style.color.blue)); expect(widget.style.color.alpha, lessThan(255)); }); + + testWidgets('Dialog default action styles', (WidgetTester tester) async { + await tester.pumpWidget(const CupertinoDialogAction( + isDefaultAction: true, + child: const Text('Ok'), + )); + + final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); + + expect(widget.style.fontWeight, equals(FontWeight.w600)); + }); + + testWidgets('Default and destructive style', (WidgetTester tester) async { + await tester.pumpWidget(const CupertinoDialogAction( + isDefaultAction: true, + isDestructiveAction: true, + child: const Text('Ok'), + )); + + final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); + + expect(widget.style.fontWeight, equals(FontWeight.w600)); + expect(widget.style.color.red, greaterThan(widget.style.color.blue)); + }); }