Use alwaysUse24HourFormat when formatting time of day#12517
Use alwaysUse24HourFormat when formatting time of day#12517yjbanov merged 6 commits intoflutter:masterfrom
Conversation
There was a problem hiding this comment.
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.
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.
Should be gone now (added the module in a different PR).
There was a problem hiding this comment.
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.
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.
(or leave it as you have it now if you think that's clearer)
There was a problem hiding this comment.
Given the first link, the last sentence is redundant. Removed it.
There was a problem hiding this comment.
interesting that timeOfDay.hourOfPeriod doesn't do this logic for you.
There was a problem hiding this comment.
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.
Done (removed else)
There was a problem hiding this comment.
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.
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.
how does is24h interact with the new flag?
There was a problem hiding this comment.
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.
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.
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.
do we only expose this for testing?
There was a problem hiding this comment.
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.
Done (used custom Navigator/MediaQuery/Localizations/Directionality).
There was a problem hiding this comment.
avoid backticks around true, false, and null.
There was a problem hiding this comment.
Reverted. This was added in a separate PR.
There was a problem hiding this comment.
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.
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