Skip to content

[material_ui] Support custom date input formatters via CalendarDelegate - #12608

Merged
auto-submit[bot] merged 20 commits into
flutter:mainfrom
Mairramer:feature/create-date-input-delegate
Sep 10, 2026
Merged

auto-submit[bot] merged 20 commits into
flutter:mainfrom
Mairramer:feature/create-date-input-delegate

Conversation

@Mairramer

@Mairramer Mairramer commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds the keyboardInputFormatters method to CalendarDelegate.

Previously, date input was strictly coupled to MaterialLocalizations. This change allows developers to provide a list of TextInputFormatters via a custom CalendarDelegate to enforce specific input masks (e.g., dd/MM/yyyy) or restrict character entry in date pickers (showDatePicker, showDateRangePicker, and InputDatePickerFormField).

Fixes flutter/flutter#83302
Fixes flutter/flutter#97134
Fixes flutter/flutter#62401
Fixes flutter/flutter#181043
Fixes flutter/flutter#115151
Fixes flutter/flutter#191639
Fixes partially flutter/flutter#150611

Port of flutter/flutter#181105

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@Mairramer

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for customizing date input formatters in the Material date picker via CalendarDelegate.keyboardInputFormatters, along with a new API sample and tests. Review feedback identifies critical compilation errors in the example code regarding unsupported enum shorthand and the use of a non-existent initialValue parameter in DropdownButtonFormField. Additionally, the feedback points out an incorrect import path in the test file, redundant inputFormatters parameters in the date picker APIs, and a potential RangeError when handling negative selection offsets in DateInputFormatter.

Comment thread packages/material_ui/example/test/date_picker/show_date_picker.2_test.dart Outdated
Comment thread packages/material_ui/lib/src/date_picker.dart Outdated
Comment thread packages/material_ui/lib/src/date_picker.dart Outdated
Comment thread packages/material_ui/lib/src/date_picker.dart Outdated
@QuncCccccc QuncCccccc added the CICD Run CI/CD label Aug 26, 2026

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Mairramer! Thanks for the contribution! Because of the volume of PRs we receive, it is a bit confusing to figure out which drafts are ready for review and which are not. So please convert the draft to ready-to-review status when it is ready so we will proceed the next step. I know there is a max limit for PR creation but let's do them one by one:) Thanks!

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 4, 2026
@Mairramer Mairramer added the CICD Run CI/CD label Sep 4, 2026
@Mairramer
Mairramer marked this pull request as ready for review September 4, 2026 16:06

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for customizing date input formatters in the Material date picker via CalendarDelegate.keyboardInputFormatters. It updates CalendarDelegate to include this method, integrates it into the date range and form field pickers, and adds a comprehensive example and tests. The review comments point out critical issues in the new example code, including invalid leading dot syntax for enum initialization, incorrect parameter usage (initialValue instead of value) in DropdownButtonFormField, and a potential RangeError in DateInputFormatter when the selection offset is negative.

Comment on lines +219 to +221
int digitsBefore = _countDigits(
newValue.text.substring(0, newValue.selection.baseOffset),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If newValue.selection.baseOffset is -1 (e.g., when the field is not focused or selection is invalid), calling substring(0, -1) will throw a RangeError. Guard against negative offsets before calling substring.

Suggested change
int digitsBefore = _countDigits(
newValue.text.substring(0, newValue.selection.baseOffset),
);
final int baseOffset = newValue.selection.baseOffset;
final int digitsBefore = baseOffset < 0
? 0
: _countDigits(newValue.text.substring(0, baseOffset));

@QuncCccccc
QuncCccccc self-requested a review September 8, 2026 21:34

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RS-LGTM since the original PR has been approved!

@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 10, 2026
@auto-submit
auto-submit Bot merged commit c437326 into flutter:main Sep 10, 2026
14 checks passed
pull Bot pushed a commit to Mattlk13/flutter that referenced this pull request Sep 11, 2026
…r#192630)

flutter/packages@8a35b16...9caa77c

2026-09-11 [email protected] [pigeon] main actor async flutter api
(flutter/packages#12729)
2026-09-10 [email protected] [image_picker] Handle a null stream
from openInputStream (flutter/packages#12718)
2026-09-10 [email protected] [material_ui]
1.2.0 sync back clean up (flutter/packages#12829)
2026-09-10 [email protected] [material_ui]
Support custom date input formatters via CalendarDelegate
(flutter/packages#12608)
2026-09-10 [email protected] [in_app_purchase_storekit] Expose
expiration date directly for subscriptions (flutter/packages#11551)
2026-09-10 [email protected] [file_selector_android] Handle a null
stream from openInputStream (flutter/packages#12716)
2026-09-10 [email protected] [pigeon] Add FFI and JNI support to
Swift and Kotlin (flutter/packages#11352)
2026-09-10 [email protected] [material_ui]
Migrate M3 Card defaults to new gen_defaults (flutter/packages#12795)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: material_ui triage-design Should be looked at in design triage

Projects

None yet

2 participants