Unverified Commit bd2ca58d authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `CupertinoPicker`dark mode text color (#100310)

Improved code
parent f5865e5c
...@@ -281,11 +281,12 @@ class _CupertinoPickerState extends State<CupertinoPicker> { ...@@ -281,11 +281,12 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final TextStyle textStyle = CupertinoTheme.of(context).textTheme.pickerTextStyle;
final Color? resolvedBackgroundColor = CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context); final Color? resolvedBackgroundColor = CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context);
assert(RenderListWheelViewport.defaultPerspective == _kDefaultPerspective); assert(RenderListWheelViewport.defaultPerspective == _kDefaultPerspective);
final Widget result = DefaultTextStyle( final Widget result = DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.pickerTextStyle, style: textStyle.copyWith(color: CupertinoDynamicColor.maybeResolve(textStyle.color, context)),
child: Stack( child: Stack(
children: <Widget>[ children: <Widget>[
Positioned.fill( Positioned.fill(
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -423,6 +424,46 @@ void main() { ...@@ -423,6 +424,46 @@ void main() {
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
}); });
testWidgets('Picker adapts to MaterialApp dark mode', (WidgetTester tester) async {
Widget _buildCupertinoPicker(Brightness brightness) {
return MaterialApp(
theme: ThemeData(brightness: brightness),
home: Align(
alignment: Alignment.topLeft,
child: SizedBox(
height: 300.0,
width: 300.0,
child: CupertinoPicker(
itemExtent: 50.0,
onSelectedItemChanged: (_) { },
children: List<Widget>.generate(3, (int index) {
return SizedBox(
height: 50.0,
width: 300.0,
child: Text(index.toString()),
);
}),
),
),
),
);
}
// CupertinoPicker with light theme.
await tester.pumpWidget(_buildCupertinoPicker(Brightness.light));
RenderParagraph paragraph = tester.renderObject(find.text('1'));
expect(paragraph.text.style!.color, CupertinoColors.label);
// Text style should not return unresolved color.
expect(paragraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
// CupertinoPicker with dark theme.
await tester.pumpWidget(_buildCupertinoPicker(Brightness.dark));
paragraph = tester.renderObject(find.text('1'));
expect(paragraph.text.style!.color, CupertinoColors.label);
// Text style should not return unresolved color.
expect(paragraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
});
group('CupertinoPickerDefaultSelectionOverlay', () { group('CupertinoPickerDefaultSelectionOverlay', () {
testWidgets('should be using directional decoration', (WidgetTester tester) async { testWidgets('should be using directional decoration', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
......
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