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> {
actions: <Widget>[
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'); }
),
]
......
......@@ -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,
......
......@@ -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));
});
}
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