mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
Fix text color for default CupertinoContextMenuAction (#144542)
## Description This PR fix the text color for the default action in a CupertiniContextMenu. Previously the dynamic color was not resolved which leads to text being blacks when theme brightness was dark. | Before | After | |--------|--------| | ![Capture dâeÌcran 2024-03-04 aÌ 14 58 45](https://github.com/flutter/flutter/assets/840911/6a06715d-b2b8-49e1-b6de-37c03b96b627) | ![Capture dâeÌcran 2024-03-04 aÌ 15 00 27](https://github.com/flutter/flutter/assets/840911/ed7c71ec-96f2-46ca-a5f6-ba3890732e33) | ## Related Issue Fixes https://github.com/flutter/flutter/issues/144492. ## Tests Adds 1 test, updates 1.
This commit is contained in:
parent
1a0dc8f1e1
commit
16d122dbe2
|
@ -89,6 +89,7 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
|
||||||
TextStyle get _textStyle {
|
TextStyle get _textStyle {
|
||||||
if (widget.isDefaultAction) {
|
if (widget.isDefaultAction) {
|
||||||
return _kActionSheetActionStyle.copyWith(
|
return _kActionSheetActionStyle.copyWith(
|
||||||
|
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context),
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,11 @@ import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Constants taken from _ContextMenuActionState.
|
// Constants taken from _ContextMenuActionState.
|
||||||
const CupertinoDynamicColor kBackgroundColor =
|
const CupertinoDynamicColor kBackgroundColor = CupertinoDynamicColor.withBrightness(
|
||||||
CupertinoDynamicColor.withBrightness(
|
|
||||||
color: Color(0xFFF1F1F1),
|
color: Color(0xFFF1F1F1),
|
||||||
darkColor: Color(0xFF212122),
|
darkColor: Color(0xFF212122),
|
||||||
);
|
);
|
||||||
const CupertinoDynamicColor kBackgroundColorPressed =
|
const CupertinoDynamicColor kBackgroundColorPressed = CupertinoDynamicColor.withBrightness(
|
||||||
CupertinoDynamicColor.withBrightness(
|
|
||||||
color: Color(0xFFDDDDDD),
|
color: Color(0xFFDDDDDD),
|
||||||
darkColor: Color(0xFF3F3F40),
|
darkColor: Color(0xFF3F3F40),
|
||||||
);
|
);
|
||||||
|
@ -117,24 +115,33 @@ void main() {
|
||||||
paints..rect(color: kBackgroundColor.darkColor));
|
paints..rect(color: kBackgroundColor.darkColor));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('icon and textStyle colors are correct out of the box',
|
testWidgets('icon and textStyle colors are correct out of the box', (WidgetTester tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
await tester.pumpWidget(getApp());
|
await tester.pumpWidget(getApp());
|
||||||
expect(getTextStyle(tester).color, CupertinoColors.label);
|
expect(getTextStyle(tester).color, CupertinoColors.label);
|
||||||
expect(getIcon(tester).color, CupertinoColors.label);
|
expect(getIcon(tester).color, CupertinoColors.label);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('icon and textStyle colors are correct for destructive actions',
|
testWidgets('icon and textStyle colors are correct for destructive actions', (WidgetTester tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
await tester.pumpWidget(getApp(isDestructiveAction: true));
|
await tester.pumpWidget(getApp(isDestructiveAction: true));
|
||||||
expect(getTextStyle(tester).color, kDestructiveActionColor);
|
expect(getTextStyle(tester).color, kDestructiveActionColor);
|
||||||
expect(getIcon(tester).color, kDestructiveActionColor);
|
expect(getIcon(tester).color, kDestructiveActionColor);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('textStyle is correct for defaultAction',
|
testWidgets('textStyle is correct for defaultAction for Brightness.light', (WidgetTester tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
await tester.pumpWidget(getApp(isDefaultAction: true));
|
await tester.pumpWidget(getApp(isDefaultAction: true));
|
||||||
expect(getTextStyle(tester).fontWeight, kDefaultActionWeight);
|
expect(getTextStyle(tester).fontWeight, kDefaultActionWeight);
|
||||||
|
final Element context = tester.element(find.byType(CupertinoContextMenuAction));
|
||||||
|
// The dynamic color should have been resolved.
|
||||||
|
expect(getTextStyle(tester).color, CupertinoColors.label.resolveFrom(context));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('textStyle is correct for defaultAction for Brightness.dark', (WidgetTester tester) async {
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/144492.
|
||||||
|
await tester.pumpWidget(getApp(isDefaultAction: true, brightness: Brightness.dark));
|
||||||
|
expect(getTextStyle(tester).fontWeight, kDefaultActionWeight);
|
||||||
|
final Element context = tester.element(find.byType(CupertinoContextMenuAction));
|
||||||
|
// The dynamic color should have been resolved.
|
||||||
|
expect(getTextStyle(tester).color, CupertinoColors.label.resolveFrom(context));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
|
|
Loading…
Reference in a new issue