-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add headerTextColor and headerNavigationButtonColor to DatePickerThemeData #161458
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
Conversation
|
I would like to point out that the flutter analyze step is currently failing due to issues unrelated to the changes introduced in this PR. These errors are also present on the upstream/master branch. The errors reported are specifically related to the missing process_runner package and undefined classes (ProcessRunner, ProcessRunnerResult) in the file test_private/bin/test_private.dart. This file has not been modified by this PR. |
|
Hey @Piinks, I noticed that the existing PR (#161483) aims to modify the header's overall color, which is great for some use cases. However, I believe a more flexible approach would be to allow separate customization for both the header text color and the navigation buttons' color. It can provides developers greater control over the look and feel of the In my implementation:
This approach ensures backward compatibility while also enhancing the theming capabilities for users who need more granular control. |
QuncCccccc
left a comment
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 a lot for the contribution:) Overall it looks good to me! Just left some comments below.
| TextStyle? get headerHelpStyle => _textTheme.labelLarge; | ||
|
|
||
| @override | ||
| Color? get headerTextColor => _colors.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.
The default values in _DatePickerDefaultsM3 are auto generated by running script. Could you help add the change in here, and then run dev/tools/gen_defaults/bin/gen_defaults.dart in the root? The change added in date_picker_template.dart will then appear here.
Running the script should help fix the linux analyze failure below.
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.
Same question here, should the default color be _colors.onSurface.withOpacity(0.60) to make sure it's backward compatible?
| TextStyle? get headerHelpStyle => _textTheme.labelSmall; | ||
|
|
||
| @override | ||
| Color? get headerTextColor => _colors.onPrimary; |
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.
Should both headerTextColor and headerNavigationButtonColor default to colors.onSurface.withOpacity(0.60) in M2 and M3?
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.
Instead of adding just headerTextColor, maybe we can change this to TextStyle subheaderTextStyle. So the default value would be _textTheme.titleSmall?.copyWith(color: colors.onSurface.withOpacity(0.60)). 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.
Thank you for the suggestion ! Aligning the default values of headerTextColor and headerNavigationButtonColor to colors.onSurface.withOpacity(0.60) for both M2 and M3 is indeed a good idea for consistency. I will update the implementation to reflect this change.
Thank you for the thoughtful suggestion! Changing headerTextColor to subheaderTextStyle makes more sense. I will incorporate this change into the PR and ensure the default value follows your suggestion (_textTheme.titleSmall?.copyWith(color: colors.onSurface.withOpacity(0.60))).
QuncCccccc
left a comment
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.
Sorry for the late response! Left some comments below:) Please let me know if there's any confusion!
| TextStyle? get headerHelpStyle => _textTheme.labelLarge; | ||
|
|
||
| @override | ||
| TextStyle? get subheaderTextStyle => _textTheme.titleSmall?.copyWith(color: _colors.onSurface.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.
Could you follow the instructions in this comment to add the same changes in date_picker_template.dart? Any changes in _DatePickerDefaultsM3 should not be hand-coded:) This will help fix the linux analyzer test.
Please let me know if there's any confusion!
| final ColorScheme colorScheme = Theme.of(context).colorScheme; | ||
| final TextTheme textTheme = Theme.of(context).textTheme; | ||
| final Color controlColor = colorScheme.onSurface.withOpacity(0.60); | ||
| final TextStyle? subHeaderTextStyle = DatePickerTheme.of(context).subheaderTextStyle; |
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 doesn't look correct? This seems never default to colorScheme.onSurface.withOpacity(0.60);, right?
I think it should be something like:
final DatePickerThemeData datePickerTheme = DatePickerTheme.of(context);
final DatePickerThemeData defaults = DatePickerTheme.defaults(context);
final TextStyle? effectiveSubheaderTextStyle = datePickerTheme.subheaderTextStyle ?? defaults.subheaderTextStyle;| 'confirmButtonStyle: ButtonStyle#00000(foregroundColor: WidgetStatePropertyAll(${const Color(0xffffff7f)}))', | ||
| 'locale: en', | ||
| 'subheaderTextStyle: TextStyle(inherit: true, size: 13.0)', | ||
| 'headerNavigationButtonColor: ${const Color(0xffffff9f)}', |
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.
Should the unit test below "DatePickerDialog uses ThemeData datePicker theme (calendar mode)" also be updated and verify whether the subheaders are correctly customized? Either updating the existing tests or adding a new unit test to verify the new properties are able to customize the subheaders is fine:)
|
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
I'm closing this PR because I mistakenly used master as the source branch. I have moved my changes to fix-date-picker-subheader and will open a new PR shortly. |
|
Using the master branch is correct: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview The main branch in flutter/flutter is a mirror of master. Master is still the source of truth. |
issue: #160591
This PR adds two new properties to
DatePickerThemeData:headerTextColor: Allows customizing the text color in the header.headerNavigationButtonColor: Allows customizing the navigation button color.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.