Fix CupertinoPickerdark mode text color (#100310)

Improved code
This commit is contained in:
Taha Tesser 2022-05-02 22:42:03 +03:00 committed by GitHub
parent f5865e5cdb
commit bd2ca58db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View File

@ -281,11 +281,12 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
@override
Widget build(BuildContext context) {
final TextStyle textStyle = CupertinoTheme.of(context).textTheme.pickerTextStyle;
final Color? resolvedBackgroundColor = CupertinoDynamicColor.maybeResolve(widget.backgroundColor, context);
assert(RenderListWheelViewport.defaultPerspective == _kDefaultPerspective);
final Widget result = DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.pickerTextStyle,
style: textStyle.copyWith(color: CupertinoDynamicColor.maybeResolve(textStyle.color, context)),
child: Stack(
children: <Widget>[
Positioned.fill(

View File

@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@ -423,6 +424,46 @@ void main() {
}, 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', () {
testWidgets('should be using directional decoration', (WidgetTester tester) async {
await tester.pumpWidget(