[Cupertino] fix dark mode for ContextMenuAction
(#92480)
This commit is contained in:
parent
6ea0b2c929
commit
12b72919f9
@ -49,8 +49,14 @@ class CupertinoContextMenuAction extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction> {
|
||||
static const Color _kBackgroundColor = Color(0xFFEEEEEE);
|
||||
static const Color _kBackgroundColorPressed = Color(0xFFDDDDDD);
|
||||
static const Color _kBackgroundColor = CupertinoDynamicColor.withBrightness(
|
||||
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 TextStyle _kActionSheetActionStyle = TextStyle(
|
||||
fontFamily: '.SF UI Text',
|
||||
@ -93,10 +99,11 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
|
||||
color: CupertinoColors.destructiveRed,
|
||||
);
|
||||
}
|
||||
return _kActionSheetActionStyle;
|
||||
return _kActionSheetActionStyle.copyWith(
|
||||
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
@ -114,7 +121,9 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
|
||||
button: true,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _isPressed ? _kBackgroundColorPressed : _kBackgroundColor,
|
||||
color: _isPressed
|
||||
? CupertinoDynamicColor.resolve(_kBackgroundColorPressed, context)
|
||||
: CupertinoDynamicColor.resolve(_kBackgroundColor, context),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16.0,
|
||||
|
@ -5,15 +5,28 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../rendering/mock_canvas.dart';
|
||||
|
||||
void main() {
|
||||
// Constants taken from _ContextMenuActionState.
|
||||
const Color _kBackgroundColor = Color(0xFFEEEEEE);
|
||||
const Color _kBackgroundColorPressed = Color(0xFFDDDDDD);
|
||||
const Color _kRegularActionColor = CupertinoColors.black;
|
||||
const CupertinoDynamicColor _kBackgroundColor = CupertinoDynamicColor.withBrightness(
|
||||
color: Color(0xFFEEEEEE),
|
||||
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 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 CupertinoContextMenuAction action = CupertinoContextMenuAction(
|
||||
key: actionKey,
|
||||
@ -25,6 +38,9 @@ void main() {
|
||||
);
|
||||
|
||||
return CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: brightness ?? Brightness.light,
|
||||
),
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: action,
|
||||
@ -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) {
|
||||
final Finder finder = find.descendant(
|
||||
of: find.byType(CupertinoContextMenuAction),
|
||||
@ -76,22 +82,34 @@ void main() {
|
||||
|
||||
testWidgets('turns grey when pressed and held', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_getApp());
|
||||
expect(_getDecoration(tester).color, _kBackgroundColor);
|
||||
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColor.color));
|
||||
|
||||
final Offset actionCenter = tester.getCenter(find.byType(CupertinoContextMenuAction));
|
||||
final TestGesture gesture = await tester.startGesture(actionCenter);
|
||||
final Offset actionCenterLight = tester.getCenter(find.byType(CupertinoContextMenuAction));
|
||||
final TestGesture gestureLight = await tester.startGesture(actionCenterLight);
|
||||
await tester.pump();
|
||||
expect(_getDecoration(tester).color, _kBackgroundColorPressed);
|
||||
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColorPressed.color));
|
||||
|
||||
await gesture.up();
|
||||
await gestureLight.up();
|
||||
await tester.pump();
|
||||
expect(_getDecoration(tester).color, _kBackgroundColor);
|
||||
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 actionCenterDark = tester.getCenter(find.byType(CupertinoContextMenuAction));
|
||||
final TestGesture gestureDark = await tester.startGesture(actionCenterDark);
|
||||
await tester.pump();
|
||||
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColorPressed.darkColor));
|
||||
|
||||
await gestureDark.up();
|
||||
await tester.pump();
|
||||
expect(find.byType(CupertinoContextMenuAction), paints..rect(color: _kBackgroundColor.darkColor));
|
||||
});
|
||||
|
||||
testWidgets('icon and textStyle colors are correct out of the box', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_getApp());
|
||||
expect(_getTextStyle(tester).color, _kRegularActionColor);
|
||||
expect(_getIcon(tester).color, _kRegularActionColor);
|
||||
expect(_getTextStyle(tester).color, CupertinoColors.label);
|
||||
expect(_getIcon(tester).color, CupertinoColors.label);
|
||||
});
|
||||
|
||||
testWidgets('icon and textStyle colors are correct for destructive actions', (WidgetTester tester) async {
|
||||
|
Loading…
x
Reference in New Issue
Block a user