Unverified Commit 07014d57 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `CupertinoDatePicker`dark mode text color (#100312)

Improved code
parent 111eb93c
...@@ -53,7 +53,9 @@ const double _kTimerPickerColumnIntrinsicWidth = 106; ...@@ -53,7 +53,9 @@ const double _kTimerPickerColumnIntrinsicWidth = 106;
TextStyle _themeTextStyle(BuildContext context, { bool isValid = true }) { TextStyle _themeTextStyle(BuildContext context, { bool isValid = true }) {
final TextStyle style = CupertinoTheme.of(context).textTheme.dateTimePickerTextStyle; final TextStyle style = CupertinoTheme.of(context).textTheme.dateTimePickerTextStyle;
return isValid ? style : style.copyWith(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)); return isValid
? style.copyWith(color: CupertinoDynamicColor.maybeResolve(style.color, context))
: style.copyWith(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context));
} }
void _animateColumnControllerToItem(FixedExtentScrollController controller, int targetItem) { void _animateColumnControllerToItem(FixedExtentScrollController controller, int targetItem) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import 'dart:ui'; import 'dart:ui';
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_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -1515,6 +1516,33 @@ void main() { ...@@ -1515,6 +1516,33 @@ void main() {
expect(lastSelectedItem, 1); expect(lastSelectedItem, 1);
handle.dispose(); handle.dispose();
}); });
testWidgets('DatePicker adapts to MaterialApp dark mode', (WidgetTester tester) async {
Widget _buildDatePicker(Brightness brightness) {
return MaterialApp(
theme: ThemeData(brightness: brightness),
home: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (DateTime neData) {},
initialDateTime: DateTime(2018, 10, 10),
),
);
}
// CupertinoDatePicker with light theme.
await tester.pumpWidget(_buildDatePicker(Brightness.light));
RenderParagraph paragraph = tester.renderObject(find.text('October').first);
expect(paragraph.text.style!.color, CupertinoColors.label);
// Text style should not return unresolved color.
expect(paragraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
// CupertinoDatePicker with dark theme.
await tester.pumpWidget(_buildDatePicker(Brightness.dark));
paragraph = tester.renderObject(find.text('October').first);
expect(paragraph.text.style!.color, CupertinoColors.label);
// Text style should not return unresolved color.
expect(paragraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
});
} }
Widget _buildPicker({ Widget _buildPicker({
......
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