Skip to content

Conversation

@avainfo
Copy link

@avainfo avainfo commented Jan 10, 2025

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.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 10, 2025
@avainfo
Copy link
Author

avainfo commented Jan 13, 2025

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.

@Piinks
Copy link
Contributor

Piinks commented Jan 15, 2025

Hey @avainfo thanks for contributing! It looks like we already have a pull request open to fix this issue: #161483

Does that look like it will resolve the issue?

@avainfo
Copy link
Author

avainfo commented Jan 16, 2025

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 DatePicker and aligns with Flutter's design philosophy of offering customizable components.

In my implementation:

  • headerTextColor allows customization of the text displaying the month and year.
  • headerNavigationButtonColor provides control over the color of the navigation buttons.

This approach ensures backward compatibility while also enhancing the theming capabilities for users who need more granular control.

Copy link
Contributor

@QuncCccccc QuncCccccc left a 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;
Copy link
Contributor

@QuncCccccc QuncCccccc Jan 22, 2025

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.

Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Author

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))).

Copy link
Contributor

@QuncCccccc QuncCccccc left a 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));
Copy link
Contributor

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;
Copy link
Contributor

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)}',
Copy link
Contributor

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:)

@flutter-dashboard
Copy link

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@avainfo
Copy link
Author

avainfo commented Feb 26, 2025

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.

@Piinks
Copy link
Contributor

Piinks commented Feb 27, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants