Fix CupertinoDatePickerdark mode text color (#100312)

Improved code
This commit is contained in:
Taha Tesser 2022-05-02 22:41:30 +03:00 committed by GitHub
parent 111eb93cba
commit 07014d5764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -53,7 +53,9 @@ const double _kTimerPickerColumnIntrinsicWidth = 106;
TextStyle _themeTextStyle(BuildContext context, { bool isValid = true }) {
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) {

View File

@ -15,6 +15,7 @@
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
@ -1515,6 +1516,33 @@ void main() {
expect(lastSelectedItem, 1);
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({