Commit 81ec553f authored by xster's avatar xster Committed by GitHub

More Cupertino dialog UI tweaks (#9960)

* is default

* hit target

* correct test name

* review note
parent 1a2d9b00
...@@ -53,11 +53,12 @@ class _CupertinoDialogDemoState extends State<CupertinoDialogDemo> { ...@@ -53,11 +53,12 @@ class _CupertinoDialogDemoState extends State<CupertinoDialogDemo> {
actions: <Widget>[ actions: <Widget>[
new CupertinoDialogAction( new CupertinoDialogAction(
child: const Text('Discard'), child: const Text('Discard'),
isDestructive: true, isDestructiveAction: true,
onPressed: () { Navigator.pop(context, 'Discard'); } onPressed: () { Navigator.pop(context, 'Discard'); }
), ),
new CupertinoDialogAction( new CupertinoDialogAction(
child: const Text('Cancel', style: const TextStyle(fontWeight: FontWeight.w600)), child: const Text('Cancel'),
isDefaultAction: true,
onPressed: () { Navigator.pop(context, 'Cancel'); } onPressed: () { Navigator.pop(context, 'Cancel'); }
), ),
] ]
......
...@@ -191,7 +191,8 @@ class CupertinoDialogAction extends StatelessWidget { ...@@ -191,7 +191,8 @@ class CupertinoDialogAction extends StatelessWidget {
/// Creates an action for an iOS-style dialog. /// Creates an action for an iOS-style dialog.
const CupertinoDialogAction({ const CupertinoDialogAction({
this.onPressed, this.onPressed,
this.isDestructive: false, this.isDefaultAction: false,
this.isDestructiveAction: false,
@required this.child, @required this.child,
}) : assert(child != null); }) : assert(child != null);
...@@ -200,10 +201,15 @@ class CupertinoDialogAction extends StatelessWidget { ...@@ -200,10 +201,15 @@ class CupertinoDialogAction extends StatelessWidget {
/// If this is set to null, the button will be disabled. /// If this is set to null, the button will be disabled.
final VoidCallback onPressed; 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. /// Whether this action destroys an object.
/// ///
/// For example, an action that deletes an email is destructive. /// For example, an action that deletes an email is destructive.
final bool isDestructive; final bool isDestructiveAction;
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
/// ///
...@@ -218,7 +224,10 @@ class CupertinoDialogAction extends StatelessWidget { ...@@ -218,7 +224,10 @@ class CupertinoDialogAction extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextStyle style = _kCupertinoDialogActionStyle; TextStyle style = _kCupertinoDialogActionStyle;
if (isDestructive) if (isDefaultAction)
style = style.copyWith(fontWeight: FontWeight.w600);
if (isDestructiveAction)
style = style.copyWith(color: _kDestructiveActionColor); style = style.copyWith(color: _kDestructiveActionColor);
if (!enabled) if (!enabled)
...@@ -226,6 +235,7 @@ class CupertinoDialogAction extends StatelessWidget { ...@@ -226,6 +235,7 @@ class CupertinoDialogAction extends StatelessWidget {
return new GestureDetector( return new GestureDetector(
onTap: onPressed, onTap: onPressed,
behavior: HitTestBehavior.opaque,
child: new Center( child: new Center(
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: style, style: style,
......
...@@ -27,7 +27,7 @@ void main() { ...@@ -27,7 +27,7 @@ void main() {
child: const Text('Cancel'), child: const Text('Cancel'),
), ),
new CupertinoDialogAction( new CupertinoDialogAction(
isDestructive: true, isDestructiveAction: true,
onPressed: () { onPressed: () {
didDelete = true; didDelete = true;
Navigator.pop(context); Navigator.pop(context);
...@@ -63,9 +63,9 @@ void main() { ...@@ -63,9 +63,9 @@ void main() {
expect(find.text('Delete'), findsNothing); 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( await tester.pumpWidget(const CupertinoDialogAction(
isDestructive: true, isDestructiveAction: true,
child: const Text('Ok'), child: const Text('Ok'),
)); ));
...@@ -74,4 +74,28 @@ void main() { ...@@ -74,4 +74,28 @@ void main() {
expect(widget.style.color.red, greaterThan(widget.style.color.blue)); expect(widget.style.color.red, greaterThan(widget.style.color.blue));
expect(widget.style.color.alpha, lessThan(255)); 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));
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment