Skip to content

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Oct 12, 2017

Add alwaysUse24HourFormat property to MediaQuery (currently not wired to dart:ui; will do it in a follow-up PR).

Drive-by changes:

  • Fixes labels on the 24-hour rings, changing them from 0-11/13-24 to 1-12/13-23 to match Android.
  • Makes TimePickerDialog public in order to support custom Localizations and MediaQuery (allows better testing and gives developers more control).

Breaking changes:

  • adds an optional alwaysUse24HourFormat parameter to some methods of MaterialLocalizations. This should only affect implementations of this interface. Users of MaterialLocalizations should not be affected.

Fixes #11994
Fixes #4815

Copy link
Contributor

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.

Copy link
Contributor

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

@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 19, 2017

PTAL:

  • Merged with @HansMuller's flutter_localizations refactoring.
  • Moved the alwaysUse24HourFormat flag to MediaQueryData class.
  • Made a drive-by fix to the ring labels (made them 1-12/13-23 to match Android), and added tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

is this expected?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor

Choose a reason for hiding this comment

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

remove return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (removed else)

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

??

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto assert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

see earlier question

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

@Hixie
Copy link
Contributor

Hixie commented Oct 20, 2017

LGTM modulo comments.

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 ## Sample code to show how to use them.

@renefloor
Copy link
Contributor

renefloor commented Oct 26, 2017

I just updated flutter last week (I can check to which version later) and now I have this bug. Can it be I got half of this feature? My device is English and I want the 24h format. I always got the 12h format, but now I get a mix. It would also be good to document how to format timestamps in other textviews.

@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 31, 2017

@renefloor this PR should fix that too. There was a regression when we moved our default localization out into package:flutter_localizations, which I discovered while working on this PR (the fix is here if you're curious about the details).

@yjbanov
Copy link
Contributor Author

yjbanov commented Nov 1, 2017

@Hixie did you want to do another pass over the PR or is your LGTM still good? The biggest change after your LGTM was 341143d where MaterialLocalizations.timeOfDayFormat becomes the single source of truth for how we format hours.

@Hixie
Copy link
Contributor

Hixie commented Nov 1, 2017

Beautiful. LGTM.

@yjbanov yjbanov merged commit f4b0ccd into flutter:master Nov 1, 2017
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
* 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
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect Android and iOS "Use 24-hour format" setting iOS users will expect Dynamic Type support

4 participants