-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Implementation of the Material Date Range Picker. #55939
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
Implementation of the Material Date Range Picker. #55939
Conversation
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.
packages/flutter/lib/src/material/pickers/date_picker_common.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart
Outdated
Show resolved
Hide resolved
actions: <Widget>[ | ||
if (orientation == Orientation.landscape) entryModeIcon, | ||
ButtonTheme( | ||
minWidth: 64, |
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 probably be consistent with usage of .0
for doubles
/// | ||
/// Note: this is not publicly exported (see pickers.dart), as it is just an | ||
/// internal component used by [showDateRangePicker]. | ||
class CalendarDateRangePicker extends StatefulWidget { |
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 this be a private class inside of another file? People can still include this directly, even though it isn't exported, of course.
Or is it for testing purposes?
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.
It was mostly because I wasn't yet ready to commit to it being part of the public API, but didn't want to add it's bulk to the already long date_range_picker_dialog.dart
. I really wish dart had a 'package private' access control for things like this.
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.
Well, it does have "library private", but the library can only be extended to multiple files with the part of
directive, which we discourage. I know what you mean though: it would be nice if things could be made private to anything in the pub package.
Like it or not, it's part of the public API, it just isn't exported with the top level include points. Anyone can use this class with:
import 'package:/flutter/src/material/pickers/calendar_date_range_picker.dart';
Sure, it's not likely, but they could.
Anyhow, it's not a big deal: I suspect that a) people are on their own if they do that, and 2) that we might want to make this a public API anyhow.
If you're not ready to make it public, though, it's probably OK to put it in the other huge file and make it private. We have plenty of those in Flutter (mostly for that reason) already. widgets/basic.dart
is 7,144 lines...
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.
Yeah, I mostly landed on "a) people are on their own if they do that". It is called out as a "DON'T" in the effective dart guide (https://dart.dev/guides/language/effective-dart/usage#dont-import-libraries-that-are-inside-the-src-directory-of-another-package), but I totally get the point that it is technically still public.
I am leaning toward leaving this way for now. That will make it slightly easier if we do want to make it public at some point.
packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart
Outdated
Show resolved
Hide resolved
|
||
/// A `TextInputFormatter` set up to format dates. | ||
/// | ||
/// Note: this is not publicly exported (see pickers.dart), as it is |
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.
Why not private?
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.
Because it is shared between the InputDatePickerFormField
and the InputDateRangePicker
which is in another file. I could move the range picker into the input_date_picker.dart
file, but InputDateRangePicker
is not a public API either.
Again a package private feature would be welcome. I didn't see many examples of how to handle this sort of situation elsewhere in the framework. Most components are as complicated as these date pickers, so they just put everything in one large files. With the date pickers that just seemed too unwieldy.
packages/flutter/lib/src/material/pickers/input_date_picker.dart
Outdated
Show resolved
Hide resolved
final WhitelistingTextInputFormatter _filterFormatter = | ||
// Only allow digits and separators (slash, dot, comma, hyphen, space). | ||
WhitelistingTextInputFormatter(RegExp(r'[\d\/\.,-\s]+')); | ||
/// Formatter that will filter out all characters except digits and date separators. |
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.
super-meta nit: doesn't have to be a doc comment. Fine to leave it though.
packages/flutter/lib/src/material/pickers/input_date_range_picker.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/input_date_range_picker.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart
Outdated
Show resolved
Hide resolved
Thanks @rami-a, I just pushed changes that I think address everything you brought up except for the landscape input dialog overflowing. Still looking into that one. What device where you seeing it on? |
I was seeing it on the iPhone 11 pro simulator, though I also saw it on the regular date picker under the same conditions. |
One possible solution, could be to put the header into a |
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.
LGTM once those last 2 issues are fixed
Didn't you just complain that the dialog should cover the safe area? 😏 Kidding aside, I am a little confused at the expectations here. Is it just the content area that should honor the safe area, but the dialog as a whole shouldn't? Or is it just the bottom safe area that is of concern? |
Possibly. I have been playing with this for a while, and the main problem is that on iOS the keyboard that we bring up for |
haha yes I realize that it sounds like I'm changing my mind. But yeah the entire dialog should extend into the safe area so that you can't see the page behind it. However the content area should honor the safe area, should be as simple as wrapping the Scaffold's body with a |
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.
LGTM
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
Outdated
Show resolved
Hide resolved
…ttings if they are set.
…e keyboard up. Also fixed more safe area issues.
return TextFormField( | ||
decoration: InputDecoration( | ||
border: const UnderlineInputBorder(), | ||
filled: true, |
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.
@darrenaustin Why is this hardcoded? If I have InputDecorationTheme with filled: false, I expect it to be false, but now it's not the case.
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.
It is following the Material Design for this picker, which calls for it to be filled. That said, we should probably defer to the ambient InputDecorationTheme
if one is set for this. We have a future theming pass that we will be doing on the date pickers that will allow for more customization, but I might be able to put together a small PR to fix this one issue.
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.
@darrenaustin Thanks. It would be great for my use case.
Why not exporting the CalendarDateRangePicker class, like CalendarDatePicker, so we can create our custom date range picker, as it was merged we don't have access to the widget, only for the showRangeDatePicker() function. I with to customize the picker as my design did. I cant see any reason why not puting the CalendarDateRangePicker class exported at public api too. |
Hi @jhionan
I did consider this, but time constraints didn't allow me to make this component ready for exposure as a publicly supported API. It is definitely on my list of things to revisit. Please open a feature request issue so we can track this. Thx. |
I exported your widget for my use, and its very functional as it is, in my case I just want the CalendarRangeDatePicker class. The only suggestion I have for a public api is making it easier to change colors. I know it can be done by changing the theme, but I feel that would be great if it also have a straight forward color selection. And good job! |
Description
This PR adds support for the Material Date Range Picker to Flutter's Material library.
This includes support for both the full screen modal dialog with a scrolling calendar grid, as well as a text input mode that has two input fields. The new API consists mostly of the function:
Which is similar to
showDatePicker
, but returns a newDateTimeRange
that describes the start and end dates of the range.Kudos to @rami-a, upon whose work this is based.
Related Issues
Fixes: #50618
Tests
Added a new
date_range_picker_test.dart
file with tests for the various features of the new picker.Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them?