Skip to content

Commit 16d122d

Browse files
authored
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 flutter/flutter#144492. ## Tests Adds 1 test, updates 1.
1 parent 1a0dc8f commit 16d122d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

packages/flutter/lib/src/cupertino/context_menu_action.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
8989
TextStyle get _textStyle {
9090
if (widget.isDefaultAction) {
9191
return _kActionSheetActionStyle.copyWith(
92+
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context),
9293
fontWeight: FontWeight.w600,
9394
);
9495
}

packages/flutter/test/cupertino/context_menu_action_test.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import 'package:flutter_test/flutter_test.dart';
1010

1111
void main() {
1212
// Constants taken from _ContextMenuActionState.
13-
const CupertinoDynamicColor kBackgroundColor =
14-
CupertinoDynamicColor.withBrightness(
13+
const CupertinoDynamicColor kBackgroundColor = CupertinoDynamicColor.withBrightness(
1514
color: Color(0xFFF1F1F1),
1615
darkColor: Color(0xFF212122),
1716
);
18-
const CupertinoDynamicColor kBackgroundColorPressed =
19-
CupertinoDynamicColor.withBrightness(
17+
const CupertinoDynamicColor kBackgroundColorPressed = CupertinoDynamicColor.withBrightness(
2018
color: Color(0xFFDDDDDD),
2119
darkColor: Color(0xFF3F3F40),
2220
);
@@ -117,24 +115,33 @@ void main() {
117115
paints..rect(color: kBackgroundColor.darkColor));
118116
});
119117

120-
testWidgets('icon and textStyle colors are correct out of the box',
121-
(WidgetTester tester) async {
118+
testWidgets('icon and textStyle colors are correct out of the box', (WidgetTester tester) async {
122119
await tester.pumpWidget(getApp());
123120
expect(getTextStyle(tester).color, CupertinoColors.label);
124121
expect(getIcon(tester).color, CupertinoColors.label);
125122
});
126123

127-
testWidgets('icon and textStyle colors are correct for destructive actions',
128-
(WidgetTester tester) async {
124+
testWidgets('icon and textStyle colors are correct for destructive actions', (WidgetTester tester) async {
129125
await tester.pumpWidget(getApp(isDestructiveAction: true));
130126
expect(getTextStyle(tester).color, kDestructiveActionColor);
131127
expect(getIcon(tester).color, kDestructiveActionColor);
132128
});
133129

134-
testWidgets('textStyle is correct for defaultAction',
135-
(WidgetTester tester) async {
130+
testWidgets('textStyle is correct for defaultAction for Brightness.light', (WidgetTester tester) async {
136131
await tester.pumpWidget(getApp(isDefaultAction: true));
137132
expect(getTextStyle(tester).fontWeight, kDefaultActionWeight);
133+
final Element context = tester.element(find.byType(CupertinoContextMenuAction));
134+
// The dynamic color should have been resolved.
135+
expect(getTextStyle(tester).color, CupertinoColors.label.resolveFrom(context));
136+
});
137+
138+
testWidgets('textStyle is correct for defaultAction for Brightness.dark', (WidgetTester tester) async {
139+
// Regression test for https://github.com/flutter/flutter/issues/144492.
140+
await tester.pumpWidget(getApp(isDefaultAction: true, brightness: Brightness.dark));
141+
expect(getTextStyle(tester).fontWeight, kDefaultActionWeight);
142+
final Element context = tester.element(find.byType(CupertinoContextMenuAction));
143+
// The dynamic color should have been resolved.
144+
expect(getTextStyle(tester).color, CupertinoColors.label.resolveFrom(context));
138145
});
139146

140147
testWidgets(

0 commit comments

Comments
 (0)