-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Use alwaysUse24HourFormat when formatting time of day #12517
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
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 code doesn't register to be told when the flag changes, which seems bad. I would recommend putting this flag in the MediaQueryData object and having the caller read that then pass in the flag to this method.
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.
you should also check that changing the state of the flag changes the actual rendered widget
|
PTAL:
|
.idea/modules.xml
Outdated
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.
is this expected?
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 be gone now (added the module in a different PR).
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.
rather than "and it has", consider "which has", since you're talking about MediaQueryData.alwaysUse24HourFormat itself rather than the value of this argument or the behaviour of this method.
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.
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 you feel it is important to link to MediaQueryData.alwaysUse24HourFormat twice, consider the more common "see also" style, as in:
/// See also:
///
/// * [MediaQueryData.alwaysUse24HourFormat], the documentation for which provides more detail.
...or something.
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.
(or leave it as you have it now if you think that's clearer)
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.
Given the first link, the last sentence is redundant. Removed it.
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.
you can remove this else
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.
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.
interesting that timeOfDay.hourOfPeriod doesn't do this logic for you.
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.
Doesn't seem like it does. It is defined as:
int get hourOfPeriod => hour - periodOffset;where hour is 0..23, and periodOffset is either 0 or 12. So the result is 0-11, rather than 12-1-11.
Actually, this logic existed before. I think it got lost during the flutter_localizations split. A-ha!
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.
remove return
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 (removed else)
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.
assert number is 0..99
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.
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 you cannot handle MediaQuery.of() returning null (which seems reasonable, many material widgets require this) then please add an assert to the build method that calls debugCheckHasMediaQuery. (See other widgets for examples of doing 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.
Done.
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.
ditto
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.
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.
??
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.
That's how the dials behave on Android, the AM dial's top position corresponds to noon (12:00), while the PM dial's top position corresponds to midnight (00:00). We had it reversed.
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.
ditto assert
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.
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.
how does is24h interact with the new flag?
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 seems weird to be able to have the double ring with the 12h mode or the single ring with 24h mode...
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.
Good points:
how does is24h interact with the new flag?
This option is only used to track whether we need to use one dial (12h) or two dials (24h). So I renamed it to use24HourDials.
It seems weird to be able to have the double ring with the 12h mode or the single ring with 24h mode.
Theoretically an implementor of a custom MaterialLocalizations could end up with a 12h/24h mix if the way they determine the 24-hour-formattedness of time was different from how the time picker does it (e.g. if they chose to not honor the 24-hour setting). So, I changed it so that MaterialLocalizations.timeOfDayFormat, which now takes alwaysUse24HourFormat, is the single source of truth of 24-hour-formattedness of time. The value of use24HourDials is now computed purely from MaterialLocalizations.timeOfDayFormat.
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.
i was a bit confused when reading this because I thought i interpreted "_initFoo" as methods that get called from initState. Maybe rename those buildFoo to make it clearer they are called every build?
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.
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 we only expose this for testing?
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.
seems weird to expose a TimePickerDialog but not a DatePickerDialog.
seems weird to expose either if they're an implementation detail of showTimePicker et al.
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 (used custom Navigator/MediaQuery/Localizations/Directionality).
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.
avoid backticks around true, false, and null.
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.
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.
see earlier question
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.
Reverted. This was added in a separate PR.
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.
you can write this test with showTimePicker, use a GlobalKey to get the context from inside the MediaQuery.
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 (used custom Navigator/MediaQuery/Localizations/Directionality).
|
I'd rather we didn't expose TimePickerDialog (just because it will confuse people who want to know how to show a time picker), but if we do expose it, we should definitely expose DatePickerDialog as well and we should thoroughly document both, in particular pointing them to the showTimePicker et al functions, probably with |
|
@renefloor this PR should fix that too. There was a regression when we moved our default localization out into |
|
Beautiful. LGTM. |
* alwaysUse24HourFormat in MediaQuery and time picker * docs; dead code * address some comments * MaterialLocalizations.timeOfDayFormat is the single source of 24-hour-formattedness * Make TimePickerDialog private again * wire up MediaQueryData.fromWindow to Window

Add
alwaysUse24HourFormatproperty toMediaQuery(currently not wired todart:ui; will do it in a follow-up PR).Drive-by changes:
TimePickerDialogpublic in order to support customLocalizationsandMediaQuery(allows better testing and gives developers more control).Breaking changes:
alwaysUse24HourFormatparameter to some methods ofMaterialLocalizations. This should only affect implementations of this interface. Users ofMaterialLocalizationsshould not be affected.Fixes #11994
Fixes #4815