diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index b8b25057ef..667cce710e 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -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) { diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index 4c2808389f..80a6f33643 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -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({