Unverified Commit 7d8d0863 authored by rami-a's avatar rami-a Committed by GitHub

Add property to theme dial label colors (#60383)

parent e1538d1b
...@@ -1127,8 +1127,8 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1127,8 +1127,8 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
TimeOfDay(hour: 22, minute: 0), TimeOfDay(hour: 22, minute: 0),
]; ];
_TappableLabel _buildTappableLabel(TextTheme textTheme, int value, String label, VoidCallback onTap) { _TappableLabel _buildTappableLabel(TextTheme textTheme, Color color, int value, String label, VoidCallback onTap) {
final TextStyle style = textTheme.subtitle1; final TextStyle style = textTheme.subtitle1.copyWith(color: color);
final double labelScaleFactor = math.min(MediaQuery.of(context).textScaleFactor, 2.0); final double labelScaleFactor = math.min(MediaQuery.of(context).textScaleFactor, 2.0);
return _TappableLabel( return _TappableLabel(
value: value, value: value,
...@@ -1141,10 +1141,11 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1141,10 +1141,11 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
); );
} }
List<_TappableLabel> _build24HourRing(TextTheme textTheme) => <_TappableLabel>[ List<_TappableLabel> _build24HourRing(TextTheme textTheme, Color color) => <_TappableLabel>[
for (final TimeOfDay timeOfDay in _twentyFourHours) for (final TimeOfDay timeOfDay in _twentyFourHours)
_buildTappableLabel( _buildTappableLabel(
textTheme, textTheme,
color,
timeOfDay.hour, timeOfDay.hour,
localizations.formatHour(timeOfDay, alwaysUse24HourFormat: media.alwaysUse24HourFormat), localizations.formatHour(timeOfDay, alwaysUse24HourFormat: media.alwaysUse24HourFormat),
() { () {
...@@ -1153,10 +1154,11 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1153,10 +1154,11 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
), ),
]; ];
List<_TappableLabel> _build12HourRing(TextTheme textTheme) => <_TappableLabel>[ List<_TappableLabel> _build12HourRing(TextTheme textTheme, Color color) => <_TappableLabel>[
for (final TimeOfDay timeOfDay in _amHours) for (final TimeOfDay timeOfDay in _amHours)
_buildTappableLabel( _buildTappableLabel(
textTheme, textTheme,
color,
timeOfDay.hour, timeOfDay.hour,
localizations.formatHour(timeOfDay, alwaysUse24HourFormat: media.alwaysUse24HourFormat), localizations.formatHour(timeOfDay, alwaysUse24HourFormat: media.alwaysUse24HourFormat),
() { () {
...@@ -1165,7 +1167,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1165,7 +1167,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
), ),
]; ];
List<_TappableLabel> _buildMinutes(TextTheme textTheme) { List<_TappableLabel> _buildMinutes(TextTheme textTheme, Color color) {
const List<TimeOfDay> _minuteMarkerValues = <TimeOfDay>[ const List<TimeOfDay> _minuteMarkerValues = <TimeOfDay>[
TimeOfDay(hour: 0, minute: 0), TimeOfDay(hour: 0, minute: 0),
TimeOfDay(hour: 0, minute: 5), TimeOfDay(hour: 0, minute: 5),
...@@ -1185,6 +1187,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1185,6 +1187,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
for (final TimeOfDay timeOfDay in _minuteMarkerValues) for (final TimeOfDay timeOfDay in _minuteMarkerValues)
_buildTappableLabel( _buildTappableLabel(
textTheme, textTheme,
color,
timeOfDay.minute, timeOfDay.minute,
localizations.formatMinute(timeOfDay), localizations.formatMinute(timeOfDay),
() { () {
...@@ -1200,6 +1203,8 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1200,6 +1203,8 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
final TimePickerThemeData pickerTheme = TimePickerTheme.of(context); final TimePickerThemeData pickerTheme = TimePickerTheme.of(context);
final Color backgroundColor = pickerTheme.dialBackgroundColor ?? themeData.colorScheme.onBackground.withOpacity(0.12); final Color backgroundColor = pickerTheme.dialBackgroundColor ?? themeData.colorScheme.onBackground.withOpacity(0.12);
final Color accentColor = pickerTheme.dialHandColor ?? themeData.colorScheme.primary; final Color accentColor = pickerTheme.dialHandColor ?? themeData.colorScheme.primary;
final Color primaryLabelColor = MaterialStateProperty.resolveAs(pickerTheme.dialTextColor, <MaterialState>{});
final Color secondaryLabelColor = MaterialStateProperty.resolveAs(pickerTheme.dialTextColor, <MaterialState>{MaterialState.selected});
List<_TappableLabel> primaryLabels; List<_TappableLabel> primaryLabels;
List<_TappableLabel> secondaryLabels; List<_TappableLabel> secondaryLabels;
int selectedDialValue; int selectedDialValue;
...@@ -1207,18 +1212,18 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1207,18 +1212,18 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
case _TimePickerMode.hour: case _TimePickerMode.hour:
if (widget.use24HourDials) { if (widget.use24HourDials) {
selectedDialValue = widget.selectedTime.hour; selectedDialValue = widget.selectedTime.hour;
primaryLabels = _build24HourRing(theme.textTheme); primaryLabels = _build24HourRing(theme.textTheme, primaryLabelColor);
secondaryLabels = _build24HourRing(theme.accentTextTheme); secondaryLabels = _build24HourRing(theme.accentTextTheme, secondaryLabelColor);
} else { } else {
selectedDialValue = widget.selectedTime.hourOfPeriod; selectedDialValue = widget.selectedTime.hourOfPeriod;
primaryLabels = _build12HourRing(theme.textTheme); primaryLabels = _build12HourRing(theme.textTheme, primaryLabelColor);
secondaryLabels = _build12HourRing(theme.accentTextTheme); secondaryLabels = _build12HourRing(theme.accentTextTheme, secondaryLabelColor);
} }
break; break;
case _TimePickerMode.minute: case _TimePickerMode.minute:
selectedDialValue = widget.selectedTime.minute; selectedDialValue = widget.selectedTime.minute;
primaryLabels = _buildMinutes(theme.textTheme); primaryLabels = _buildMinutes(theme.textTheme, primaryLabelColor);
secondaryLabels = _buildMinutes(theme.accentTextTheme); secondaryLabels = _buildMinutes(theme.accentTextTheme, secondaryLabelColor);
break; break;
} }
......
...@@ -41,6 +41,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -41,6 +41,7 @@ class TimePickerThemeData with Diagnosticable {
this.dayPeriodColor, this.dayPeriodColor,
this.dialHandColor, this.dialHandColor,
this.dialBackgroundColor, this.dialBackgroundColor,
this.dialTextColor,
this.entryModeIconColor, this.entryModeIconColor,
this.hourMinuteTextStyle, this.hourMinuteTextStyle,
this.dayPeriodTextStyle, this.dayPeriodTextStyle,
...@@ -121,6 +122,16 @@ class TimePickerThemeData with Diagnosticable { ...@@ -121,6 +122,16 @@ class TimePickerThemeData with Diagnosticable {
/// [ColorScheme.primary]. /// [ColorScheme.primary].
final Color dialBackgroundColor; final Color dialBackgroundColor;
/// The color of the dial text that represents specific hours and minutes.
///
/// If [dialTextColor] is a [MaterialStateColor], then the effective
/// text color can depend on the [MaterialState.selected] state, i.e. if the
/// text is selected or not.
///
/// By default the overall theme's `textTheme` color is used when the text is
/// selected and `accentTextTheme` color is used when it's not selected.
final Color dialTextColor;
/// The color of the entry mode [IconButton]. /// The color of the entry mode [IconButton].
/// ///
/// If this is null, the time picker defaults to /// If this is null, the time picker defaults to
...@@ -199,6 +210,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -199,6 +210,7 @@ class TimePickerThemeData with Diagnosticable {
Color dayPeriodColor, Color dayPeriodColor,
Color dialHandColor, Color dialHandColor,
Color dialBackgroundColor, Color dialBackgroundColor,
Color dialTextColor,
Color entryModeIconColor, Color entryModeIconColor,
TextStyle hourMinuteTextStyle, TextStyle hourMinuteTextStyle,
TextStyle dayPeriodTextStyle, TextStyle dayPeriodTextStyle,
...@@ -217,6 +229,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -217,6 +229,7 @@ class TimePickerThemeData with Diagnosticable {
dayPeriodColor: dayPeriodColor ?? this.dayPeriodColor, dayPeriodColor: dayPeriodColor ?? this.dayPeriodColor,
dialHandColor: dialHandColor ?? this.dialHandColor, dialHandColor: dialHandColor ?? this.dialHandColor,
dialBackgroundColor: dialBackgroundColor ?? this.dialBackgroundColor, dialBackgroundColor: dialBackgroundColor ?? this.dialBackgroundColor,
dialTextColor: dialTextColor ?? this.dialTextColor,
entryModeIconColor: entryModeIconColor ?? this.entryModeIconColor, entryModeIconColor: entryModeIconColor ?? this.entryModeIconColor,
hourMinuteTextStyle: hourMinuteTextStyle ?? this.hourMinuteTextStyle, hourMinuteTextStyle: hourMinuteTextStyle ?? this.hourMinuteTextStyle,
dayPeriodTextStyle: dayPeriodTextStyle ?? this.dayPeriodTextStyle, dayPeriodTextStyle: dayPeriodTextStyle ?? this.dayPeriodTextStyle,
...@@ -256,6 +269,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -256,6 +269,7 @@ class TimePickerThemeData with Diagnosticable {
dayPeriodColor: Color.lerp(a?.dayPeriodColor, b?.dayPeriodColor, t), dayPeriodColor: Color.lerp(a?.dayPeriodColor, b?.dayPeriodColor, t),
dialHandColor: Color.lerp(a?.dialHandColor, b?.dialHandColor, t), dialHandColor: Color.lerp(a?.dialHandColor, b?.dialHandColor, t),
dialBackgroundColor: Color.lerp(a?.dialBackgroundColor, b?.dialBackgroundColor, t), dialBackgroundColor: Color.lerp(a?.dialBackgroundColor, b?.dialBackgroundColor, t),
dialTextColor: Color.lerp(a?.dialTextColor, b?.dialTextColor, t),
entryModeIconColor: Color.lerp(a?.entryModeIconColor, b?.entryModeIconColor, t), entryModeIconColor: Color.lerp(a?.entryModeIconColor, b?.entryModeIconColor, t),
hourMinuteTextStyle: TextStyle.lerp(a?.hourMinuteTextStyle, b?.hourMinuteTextStyle, t), hourMinuteTextStyle: TextStyle.lerp(a?.hourMinuteTextStyle, b?.hourMinuteTextStyle, t),
dayPeriodTextStyle: TextStyle.lerp(a?.dayPeriodTextStyle, b?.dayPeriodTextStyle, t), dayPeriodTextStyle: TextStyle.lerp(a?.dayPeriodTextStyle, b?.dayPeriodTextStyle, t),
...@@ -278,6 +292,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -278,6 +292,7 @@ class TimePickerThemeData with Diagnosticable {
dayPeriodColor, dayPeriodColor,
dialHandColor, dialHandColor,
dialBackgroundColor, dialBackgroundColor,
dialTextColor,
entryModeIconColor, entryModeIconColor,
hourMinuteTextStyle, hourMinuteTextStyle,
dayPeriodTextStyle, dayPeriodTextStyle,
...@@ -304,6 +319,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -304,6 +319,7 @@ class TimePickerThemeData with Diagnosticable {
&& other.dayPeriodColor == dayPeriodColor && other.dayPeriodColor == dayPeriodColor
&& other.dialHandColor == dialHandColor && other.dialHandColor == dialHandColor
&& other.dialBackgroundColor == dialBackgroundColor && other.dialBackgroundColor == dialBackgroundColor
&& other.dialTextColor == dialTextColor
&& other.entryModeIconColor == entryModeIconColor && other.entryModeIconColor == entryModeIconColor
&& other.hourMinuteTextStyle == hourMinuteTextStyle && other.hourMinuteTextStyle == hourMinuteTextStyle
&& other.dayPeriodTextStyle == dayPeriodTextStyle && other.dayPeriodTextStyle == dayPeriodTextStyle
...@@ -325,6 +341,7 @@ class TimePickerThemeData with Diagnosticable { ...@@ -325,6 +341,7 @@ class TimePickerThemeData with Diagnosticable {
properties.add(ColorProperty('dayPeriodColor', dayPeriodColor, defaultValue: null)); properties.add(ColorProperty('dayPeriodColor', dayPeriodColor, defaultValue: null));
properties.add(ColorProperty('dialHandColor', dialHandColor, defaultValue: null)); properties.add(ColorProperty('dialHandColor', dialHandColor, defaultValue: null));
properties.add(ColorProperty('dialBackgroundColor', dialBackgroundColor, defaultValue: null)); properties.add(ColorProperty('dialBackgroundColor', dialBackgroundColor, defaultValue: null));
properties.add(ColorProperty('dialTextColor', dialTextColor, defaultValue: null));
properties.add(ColorProperty('entryModeIconColor', entryModeIconColor, defaultValue: null)); properties.add(ColorProperty('entryModeIconColor', entryModeIconColor, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('hourMinuteTextStyle', hourMinuteTextStyle, defaultValue: null)); properties.add(DiagnosticsProperty<TextStyle>('hourMinuteTextStyle', hourMinuteTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('dayPeriodTextStyle', dayPeriodTextStyle, defaultValue: null)); properties.add(DiagnosticsProperty<TextStyle>('dayPeriodTextStyle', dayPeriodTextStyle, defaultValue: null));
......
...@@ -26,8 +26,7 @@ void main() { ...@@ -26,8 +26,7 @@ void main() {
expect(timePickerTheme.dayPeriodColor, null); expect(timePickerTheme.dayPeriodColor, null);
expect(timePickerTheme.dialHandColor, null); expect(timePickerTheme.dialHandColor, null);
expect(timePickerTheme.dialBackgroundColor, null); expect(timePickerTheme.dialBackgroundColor, null);
expect(timePickerTheme.dialHandColor, null); expect(timePickerTheme.dialTextColor, null);
expect(timePickerTheme.dialBackgroundColor, null);
expect(timePickerTheme.entryModeIconColor, null); expect(timePickerTheme.entryModeIconColor, null);
expect(timePickerTheme.hourMinuteTextStyle, null); expect(timePickerTheme.hourMinuteTextStyle, null);
expect(timePickerTheme.dayPeriodTextStyle, null); expect(timePickerTheme.dayPeriodTextStyle, null);
...@@ -61,6 +60,7 @@ void main() { ...@@ -61,6 +60,7 @@ void main() {
dayPeriodColor: Color(0xFFFFFFFF), dayPeriodColor: Color(0xFFFFFFFF),
dialHandColor: Color(0xFFFFFFFF), dialHandColor: Color(0xFFFFFFFF),
dialBackgroundColor: Color(0xFFFFFFFF), dialBackgroundColor: Color(0xFFFFFFFF),
dialTextColor: Color(0xFFFFFFFF),
entryModeIconColor: Color(0xFFFFFFFF), entryModeIconColor: Color(0xFFFFFFFF),
hourMinuteTextStyle: TextStyle(), hourMinuteTextStyle: TextStyle(),
dayPeriodTextStyle: TextStyle(), dayPeriodTextStyle: TextStyle(),
...@@ -84,6 +84,7 @@ void main() { ...@@ -84,6 +84,7 @@ void main() {
'dayPeriodColor: Color(0xffffffff)', 'dayPeriodColor: Color(0xffffffff)',
'dialHandColor: Color(0xffffffff)', 'dialHandColor: Color(0xffffffff)',
'dialBackgroundColor: Color(0xffffffff)', 'dialBackgroundColor: Color(0xffffffff)',
'dialTextColor: Color(0xffffffff)',
'entryModeIconColor: Color(0xffffffff)', 'entryModeIconColor: Color(0xffffffff)',
'hourMinuteTextStyle: TextStyle(<all styles inherited>)', 'hourMinuteTextStyle: TextStyle(<all styles inherited>)',
'dayPeriodTextStyle: TextStyle(<all styles inherited>)', 'dayPeriodTextStyle: TextStyle(<all styles inherited>)',
...@@ -152,6 +153,21 @@ void main() { ...@@ -152,6 +153,21 @@ void main() {
.merge(Typography.material2014().black.overline), .merge(Typography.material2014().black.overline),
); );
final CustomPaint dialPaint = tester.widget(findDialPaint);
final dynamic dialPainter = dialPaint.painter;
final List<dynamic> primaryLabels = dialPainter.primaryLabels as List<dynamic>;
expect(
primaryLabels.first.painter.text.style,
Typography.material2014().englishLike.subhead
.merge(Typography.material2014().black.subhead),
);
final List<dynamic> secondaryLabels = dialPainter.secondaryLabels as List<dynamic>;
expect(
secondaryLabels.first.painter.text.style,
Typography.material2014().englishLike.subhead
.merge(Typography.material2014().white.subhead),
);
final Material hourMaterial = _textMaterial(tester, '7'); final Material hourMaterial = _textMaterial(tester, '7');
expect(hourMaterial.color, defaultTheme.colorScheme.primary.withOpacity(0.12)); expect(hourMaterial.color, defaultTheme.colorScheme.primary.withOpacity(0.12));
expect(hourMaterial.shape, const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)))); expect(hourMaterial.shape, const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))));
...@@ -276,6 +292,23 @@ void main() { ...@@ -276,6 +292,23 @@ void main() {
.merge(timePickerTheme.helpTextStyle), .merge(timePickerTheme.helpTextStyle),
); );
final CustomPaint dialPaint = tester.widget(findDialPaint);
final dynamic dialPainter = dialPaint.painter;
final List<dynamic> primaryLabels = dialPainter.primaryLabels as List<dynamic>;
expect(
primaryLabels.first.painter.text.style,
Typography.material2014().englishLike.subhead
.merge(Typography.material2014().black.subhead)
.copyWith(color: _unselectedColor),
);
final List<dynamic> secondaryLabels = dialPainter.secondaryLabels as List<dynamic>;
expect(
secondaryLabels.first.painter.text.style,
Typography.material2014().englishLike.subhead
.merge(Typography.material2014().white.subhead)
.copyWith(color: _selectedColor),
);
final Material hourMaterial = _textMaterial(tester, '7'); final Material hourMaterial = _textMaterial(tester, '7');
expect(hourMaterial.color, _selectedColor); expect(hourMaterial.color, _selectedColor);
expect(hourMaterial.shape, timePickerTheme.hourMinuteShape); expect(hourMaterial.shape, timePickerTheme.hourMinuteShape);
...@@ -343,6 +376,7 @@ TimePickerThemeData _timePickerTheme() { ...@@ -343,6 +376,7 @@ TimePickerThemeData _timePickerTheme() {
dayPeriodColor: materialStateColor, dayPeriodColor: materialStateColor,
dialHandColor: Colors.brown, dialHandColor: Colors.brown,
dialBackgroundColor: Colors.pinkAccent, dialBackgroundColor: Colors.pinkAccent,
dialTextColor: materialStateColor,
entryModeIconColor: Colors.red, entryModeIconColor: Colors.red,
hourMinuteTextStyle: const TextStyle(fontSize: 8.0), hourMinuteTextStyle: const TextStyle(fontSize: 8.0),
dayPeriodTextStyle: const TextStyle(fontSize: 8.0), dayPeriodTextStyle: const TextStyle(fontSize: 8.0),
...@@ -426,3 +460,8 @@ IconButton _entryModeIconButton(WidgetTester tester) { ...@@ -426,3 +460,8 @@ IconButton _entryModeIconButton(WidgetTester tester) {
RenderParagraph _textRenderParagraph(WidgetTester tester, String text) { RenderParagraph _textRenderParagraph(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.text(text).first).renderObject as RenderParagraph; return tester.element<StatelessElement>(find.text(text).first).renderObject as RenderParagraph;
} }
final Finder findDialPaint = find.descendant(
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_Dial'),
matching: find.byWidgetPredicate((Widget w) => w is CustomPaint),
);
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