-
Notifications
You must be signed in to change notification settings - Fork 28.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify toggle mode style with DatePickerTheme #164102
base: master
Are you sure you want to change the base?
Conversation
9d6a702
to
584b0a1
Compare
I implemented this new feature before seeing that issue #160591 requested a similar feature. That issue already has a linked PR (#161458), but that PR doesn't seem to have received updates since January 24, so my PR could be a valid implementation for both issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! Overall this looks good to me! Just left some comments below.
/// | ||
/// The [TextStyle.color] of [toggleModeStyle] is not used, [toggleModeForegroundColor] | ||
/// is used instead. | ||
final TextStyle? toggleModeStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think if toggleButtonTextStyle
would be more straightforward to understand? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/// Overrides the default color used for text labels and icons of toggle mode button. | ||
/// | ||
/// This is used instead of the [TextStyle.color] property of [toggleModeStyle]. | ||
final Color? toggleModeForegroundColor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix #160591, I think we'd better also apply this color to the month pick button. As for naming, I think subHeaderForegroundColor
would be more straightforward to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
- Add properties to DatePickerThemeData: - `toggleButtonTextStyle` allow customization on _DatePickerModeToggleButton TextStyle; - `subHeaderForegroundColor` allow changing the color of both button and Icons with consistency; - Compatible with existing code by the use of defaults; - Adjust test to cover new properties Ref flutter#163866 Ref flutter#160591
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update! Left some comments below. Please let me know if there's any questions:)
@@ -72,5 +71,7 @@ | |||
"md.comp.date-picker.modal.year-selection.year.unselected.focus.state-layer.color": "onSurfaceVariant", | |||
"md.comp.date-picker.modal.year-selection.year.unselected.hover.state-layer.color": "onSurfaceVariant", | |||
"md.comp.date-picker.modal.year-selection.year.unselected.label-text.color": "onSurfaceVariant", | |||
"md.comp.date-picker.modal.year-selection.year.unselected.pressed.state-layer.color": "onSurfaceVariant" | |||
"md.comp.date-picker.modal.year-selection.year.unselected.pressed.state-layer.color": "onSurfaceVariant", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This json file is generated from internal google, please don't edit it manually:)
@@ -62,6 +62,14 @@ class _${blockName}DefaultsM3 extends DatePickerThemeData { | |||
@override | |||
Color? get backgroundColor => ${componentColor("md.comp.date-picker.modal.container")}; | |||
|
|||
@override | |||
Color? get subHeaderForegroundColor => ${componentColor("md.comp.date-picker.modal.sub.header.foreground")}.withOpacity(0.60); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the existing token instead of adding new tokens manually:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense. This part was a bit confusing to me. So I should use something like md.comp.date-picker.modal.weekdays.label-text
for subHeaderForegroundColor
and md.comp.date-picker.modal.range-selection.month.subhead
for toggleButtonTextStyle
? Thats it?
@@ -458,12 +459,12 @@ class _DatePickerModeToggleButtonState extends State<_DatePickerModeToggleButton | |||
child: Text( | |||
widget.title, | |||
overflow: TextOverflow.ellipsis, | |||
style: textTheme.titleSmall?.copyWith(color: controlColor), | |||
style: buttonTextStyle?.apply(color: toggleModeForegroundColor), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we provide a toggleButtonTextStyle
with a custom text color in date picker theme, but don't provide a subHeaderForegroundColor
in the date picker theme, this change will cause that the customized text color is not respected, and the text color always defaults to the default subHeaderForegroundColor
.
For the text color here, ideally, I think we want to firstly check whether theme's toggleButtonTextStyle's color is empty, if not empty, we respect the color value; but if empty, then check whether theme's subheaderForegroundColor is empty, if not empty, text color should respect it; if empty, we should go to defaults.toggleButtonTextStyle, if still empty, we should check defaults.subHeaderForegroundColor
. Does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeahh, it makes sense. I'm gonna implement it!
toggleModeStyle
allow customization on _DatePickerModeToggleButton TextStyle;toggleModeForegroundColor
allow changing the color of both button and Icon with consistency;How to customize toggle mode style before:
Now:
Ref #163866
Ref #160591
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.