Unverified Commit 12b72919 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

[Cupertino] fix dark mode for `ContextMenuAction` (#92480)

parent 6ea0b2c9
...@@ -49,8 +49,14 @@ class CupertinoContextMenuAction extends StatefulWidget { ...@@ -49,8 +49,14 @@ class CupertinoContextMenuAction extends StatefulWidget {
} }
class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction> { class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction> {
static const Color _kBackgroundColor = Color(0xFFEEEEEE); static const Color _kBackgroundColor = CupertinoDynamicColor.withBrightness(
static const Color _kBackgroundColorPressed = Color(0xFFDDDDDD); color: Color(0xFFEEEEEE),
darkColor: Color(0xFF212122),
);
static const Color _kBackgroundColorPressed = CupertinoDynamicColor.withBrightness(
color: Color(0xFFDDDDDD),
darkColor: Color(0xFF3F3F40),
);
static const double _kButtonHeight = 56.0; static const double _kButtonHeight = 56.0;
static const TextStyle _kActionSheetActionStyle = TextStyle( static const TextStyle _kActionSheetActionStyle = TextStyle(
fontFamily: '.SF UI Text', fontFamily: '.SF UI Text',
...@@ -93,10 +99,11 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction> ...@@ -93,10 +99,11 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
color: CupertinoColors.destructiveRed, color: CupertinoColors.destructiveRed,
); );
} }
return _kActionSheetActionStyle; return _kActionSheetActionStyle.copyWith(
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context)
);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
...@@ -114,7 +121,9 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction> ...@@ -114,7 +121,9 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
button: true, button: true,
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: _isPressed ? _kBackgroundColorPressed : _kBackgroundColor, color: _isPressed
? CupertinoDynamicColor.resolve(_kBackgroundColorPressed, context)
: CupertinoDynamicColor.resolve(_kBackgroundColor, context),
), ),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 16.0, vertical: 16.0,
......
...@@ -5,15 +5,28 @@ ...@@ -5,15 +5,28 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
void main() { void main() {
// Constants taken from _ContextMenuActionState. // Constants taken from _ContextMenuActionState.
const Color _kBackgroundColor = Color(0xFFEEEEEE); const CupertinoDynamicColor _kBackgroundColor = CupertinoDynamicColor.withBrightness(
const Color _kBackgroundColorPressed = Color(0xFFDDDDDD); color: Color(0xFFEEEEEE),
const Color _kRegularActionColor = CupertinoColors.black; darkColor: Color(0xFF212122),
);
// static const Color _kBackgroundColorPressed = Color(0xFFDDDDDD);
const CupertinoDynamicColor _kBackgroundColorPressed = CupertinoDynamicColor.withBrightness(
color: Color(0xFFDDDDDD),
darkColor: Color(0xFF3F3F40),
);
const Color _kDestructiveActionColor = CupertinoColors.destructiveRed; const Color _kDestructiveActionColor = CupertinoColors.destructiveRed;
const FontWeight _kDefaultActionWeight = FontWeight.w600; const FontWeight _kDefaultActionWeight = FontWeight.w600;
Widget _getApp({VoidCallback? onPressed, bool isDestructiveAction = false, bool isDefaultAction = false}) { Widget _getApp({
VoidCallback? onPressed,
bool isDestructiveAction = false,
bool isDefaultAction = false,
Brightness? brightness,
}) {
final UniqueKey actionKey = UniqueKey(); final UniqueKey actionKey = UniqueKey();
final CupertinoContextMenuAction action = CupertinoContextMenuAction( final CupertinoContextMenuAction action = CupertinoContextMenuAction(
key: actionKey, key: actionKey,
...@@ -25,6 +38,9 @@ void main() { ...@@ -25,6 +38,9 @@ void main() {
); );
return CupertinoApp( return CupertinoApp(
theme: CupertinoThemeData(
brightness: brightness ?? Brightness.light,
),
home: CupertinoPageScaffold( home: CupertinoPageScaffold(
child: Center( child: Center(
child: action, child: action,
...@@ -33,16 +49,6 @@ void main() { ...@@ -33,16 +49,6 @@ void main() {
); );
} }
BoxDecoration _getDecoration(WidgetTester tester) {
final Finder finder = find.descendant(
of: find.byType(CupertinoContextMenuAction),
matching: find.byType(Container),
);
expect(finder, findsOneWidget);
final Container container = tester.widget(finder);
return container.decoration! as BoxDecoration;
}
TextStyle _getTextStyle(WidgetTester tester) { TextStyle _getTextStyle(WidgetTester tester) {
final Finder finder = find.descendant( final Finder finder = find.descendant(
of: find.byType(CupertinoContextMenuAction), of: find.byType(CupertinoContextMenuAction),
...@@ -76,22 +82,34 @@ void main() { ...@@ -76,22 +82,34 @@ void main() {
testWidgets('turns grey when pressed and held', (WidgetTester tester) async { testWidgets('turns grey when pressed and held', (WidgetTester tester) async {
await tester.pumpWidget(_getApp()); await tester.pumpWidget(_getApp());
expect(_getDecoration(tester).color, _kBackgroundColor); expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColor.color));
final Offset actionCenterLight = tester.getCenter(find.byType(CupertinoContextMenuAction));
final TestGesture gestureLight = await tester.startGesture(actionCenterLight);
await tester.pump();
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColorPressed.color));
await gestureLight.up();
await tester.pump();
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColor.color));
await tester.pumpWidget(_getApp(brightness: Brightness.dark));
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColor.darkColor));
final Offset actionCenter = tester.getCenter(find.byType(CupertinoContextMenuAction)); final Offset actionCenterDark = tester.getCenter(find.byType(CupertinoContextMenuAction));
final TestGesture gesture = await tester.startGesture(actionCenter); final TestGesture gestureDark = await tester.startGesture(actionCenterDark);
await tester.pump(); await tester.pump();
expect(_getDecoration(tester).color, _kBackgroundColorPressed); expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColorPressed.darkColor));
await gesture.up(); await gestureDark.up();
await tester.pump(); await tester.pump();
expect(_getDecoration(tester).color, _kBackgroundColor); expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColor.darkColor));
}); });
testWidgets('icon and textStyle colors are correct out of the box', (WidgetTester tester) async { testWidgets('icon and textStyle colors are correct out of the box', (WidgetTester tester) async {
await tester.pumpWidget(_getApp()); await tester.pumpWidget(_getApp());
expect(_getTextStyle(tester).color, _kRegularActionColor); expect(_getTextStyle(tester).color, CupertinoColors.label);
expect(_getIcon(tester).color, _kRegularActionColor); expect(_getIcon(tester).color, CupertinoColors.label);
}); });
testWidgets('icon and textStyle colors are correct for destructive actions', (WidgetTester tester) async { testWidgets('icon and textStyle colors are correct for destructive actions', (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