Commit 70514385 authored by Riccardo Ratta's avatar Riccardo Ratta Committed by LongCatIsLooong

Make font semibold when isDefaultAction is true in CupertinoDialogAction (#31308)

Make font semibold when isDefaultAction is true in CupertinoDialogAction
parent fc6dfe53
......@@ -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);
}
......
......@@ -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 {
......
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