Repository navigation
Add didChangeAlwaysUse24HourFormat to WidgetsBinding and update MediaQuery - #196117
auto-submit[bot] merged 8 commits into
Conversation
…Query Part of flutter#194637 Follow-up to flutter#194670 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. ## Description This PR introduces the framework layer integration (Part 2) for runtime 24-hour time format changes, building upon the engine API landed in flutter#194670. ### Changes 1. **`RendererBinding` (`packages/flutter/lib/src/rendering/binding.dart`)**: - Registered `platformDispatcher.onAlwaysUse24HourFormatChanged = handleAlwaysUse24HourFormatChanged;`. - Added `@protected void handleAlwaysUse24HourFormatChanged() {}`. 2. **`WidgetsBindingObserver` (`packages/flutter/lib/src/widgets/binding.dart`)**: - Added `void didChangeAlwaysUse24HourFormat() {}`. 3. **`WidgetsBinding` (`packages/flutter/lib/src/widgets/binding.dart`)**: - Overrode `handleAlwaysUse24HourFormatChanged()` to dispatch `observer.didChangeAlwaysUse24HourFormat()` to all registered observers. 4. **`MediaQuery` (`packages/flutter/lib/src/widgets/media_query.dart`)**: - In `_MediaQueryFromViewState`, implemented `didChangeAlwaysUse24HourFormat()` to trigger `_updateData()` when root view's format changes, causing widgets depending on `MediaQuery.alwaysUse24HourFormatOf(context)` to rebuild with the updated preference. - Updated doc comments on `MediaQueryData.fromView` to list `WidgetsBindingObserver.didChangeAlwaysUse24HourFormat` and `dart:ui.PlatformDispatcher.onAlwaysUse24HourFormatChanged`. 5. **`TestPlatformDispatcher` (`packages/flutter_test/lib/src/window.dart`)**: - Forwarded `onAlwaysUse24HourFormatChanged` getter/setter. - Updated `alwaysUse24HourFormatTestValue` and `clearAlwaysUse24HourTestValue` to invoke `onAlwaysUse24HourFormatChanged`. 6. **Unit Tests**: - `packages/flutter/test/widgets/binding_test.dart`: Added test `didChangeAlwaysUse24HourFormat` verifying observer dispatch and error handling. - `packages/flutter/test/widgets/media_query_test.dart`: Added test verifying `MediaQuery.fromView` updates when `alwaysUse24HourFormat` changes at runtime. - `packages/flutter_test/test/platform_dispatcher_test.dart`: Added test verifying `TestPlatformDispatcher.alwaysUse24HourFormatTestValue` triggers `WidgetsBindingObserver.didChangeAlwaysUse24HourFormat`. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
|
Hi @chunhtai and @victorsanni, Following the landed engine API in #194670, this is Part 2 introducing the framework layer integration ( All local analysis and unit tests are passing cleanly. Ready for review whenever you have a moment. Thank you! |
There was a problem hiding this comment.
Code Review
This pull request introduces support for reacting to changes in the platform's 24-hour format setting. It adds onAlwaysUse24HourFormatChanged handling to RendererBinding, introduces didChangeAlwaysUse24HourFormat to WidgetsBindingObserver, and updates MediaQuery to rebuild when this setting changes. Additionally, it updates TestPlatformDispatcher to support testing this behavior and includes corresponding unit tests. I have no feedback to provide.
victorsanni
left a comment
There was a problem hiding this comment.
does this mean we can remove alwaysUse24HourFormat from _viewMetrics in foundation/debug.dart
…tformDispatcher per review
|
Yes, exactly! Now that I've decoupled |
chunhtai
left a comment
There was a problem hiding this comment.
mostly LGTM. left one comment about test
| } | ||
|
|
||
| @override | ||
| void didChangeAlwaysUse24HourFormat() { |
There was a problem hiding this comment.
since we also implemented the new API on rentrant observer, we should make sure the test
"Rentrant observer callbacks do not result in exceptions"
calls the handleAlwaysUse24HourFormatChanged
There was a problem hiding this comment.
Done! Added WidgetsBinding.instance.handleAlwaysUse24HourFormatChanged() to the reentrant test in commit b0ae14f9cf, and all binding unit tests are passing cleanly.
|
is this the final PR? we should update the pr description to fix the issue |
victorsanni
left a comment
There was a problem hiding this comment.
LGTM with a doc suggestion.
|
Thanks @victorsanni and @chunhtai for the reviews! In commit
Regarding whether this is the final PR and how we should track the remaining work: Because those embedder updates are required to completely resolve the issue on physical devices, we should keep this PR as For the upcoming embedder implementations, I personally think doing separate PRs (Part 3 for Android, Part 4 for iOS, Part 5 for Web) would be the best approach. That way:
Let me know if this sounds good to you both, or if you'd prefer a single combined PR instead. Happy to follow whichever approach you and Victor prefer! |
|
Thanks for explanation, the current pr description sg then |
victorsanni
left a comment
There was a problem hiding this comment.
CI is failing because of unformatted lines in media_query_test.dart and window.dart, can you fix and re-request reviews?
| // The 24 hour format announces onAlwaysUse24HourFormatChanged and | ||
| // onPlatformConfigurationChanged, and onMetricsChanged is what tells the | ||
| // framework to re-read it. | ||
| // onPlatformConfigurationChanged. |
There was a problem hiding this comment.
should we also update widgets/debug_view_metrics_override_test.dart? i.e _NotificationRecorder and the test 'tells the framework only about what changed' in the 'propagation' group, which guards end-to-end WidgetsBindingObserver notification isolation.
There was a problem hiding this comment.
Done! Updated _NotificationRecorder with alwaysUse24HourFormat and added the corresponding assertions to 'tells the framework only about what changed' in commit fd07667. All propagation tests passing cleanly.
| expect(widthBuildCount, 2); | ||
| expect(heightBuildCount, 2); | ||
| }); | ||
|
|
There was a problem hiding this comment.
also update existing tests
- 'MediaQuery.fromView updates on notifications (no parent data)'
- 'MediaQuery.fromView updates on notifications (with parent data)'
with alwaysUse24HourFormatTestValue assertions.
There was a problem hiding this comment.
Done! Added alwaysUse24HourFormatTestValue assertions to both tests in commit fd07667, verifying dynamic updates without parent data and isolation when wrapped with parent data.
…se24HourFormat assertions per review
|
Thanks @victorsanni and @chunhtai! All review comments have been addressed and fully formatted in commit fd07667 (including |
|
autosubmit label was removed for flutter/flutter/196117, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
auto label is removed for flutter/flutter/196117, Failed to enqueue flutter/flutter/196117 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
Hi @victorsanni and @chunhtai, All CI presubmits and internal Google testing have completed with 100% green! 🎉 When
Because this PR originates from a fork, the Could one of you please approve/trigger the workflow runs and re-apply |
|
auto label is removed for flutter/flutter/196117, Failed to enqueue flutter/flutter/196117 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
Hi @victorsanni, Thanks for applying the Looking at the GitHub Actions runs, because Since all presubmits, CI shards, Google testing, and approvals are 100% green and completed, could you please either approve the pending workflow runs or directly Squash and merge the PR? Thank you so much! |
|
auto label is removed for flutter/flutter/196117, Failed to enqueue flutter/flutter/196117 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
auto label is removed for flutter/flutter/196117, Failed to enqueue flutter/flutter/196117 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
Hi @victorsanni and @chunhtai, All CI presubmits, tree checks, and internal Google testing have now finished with 100% green! 🎉 Currently, the Whenever you have a moment today, could you please click Approve and run on the pending workflow runs, or directly Squash and merge? Thank you so much! |
Part of #194637
Follow-up to #194670
cc @chunhtai @victorsanni
Pre-launch Checklist
///).Description
This PR introduces the framework layer integration (Part 2) for runtime 24-hour time format changes, building upon the engine API landed in #194670.
Changes
RendererBinding(packages/flutter/lib/src/rendering/binding.dart):platformDispatcher.onAlwaysUse24HourFormatChanged = handleAlwaysUse24HourFormatChanged;.@protected void handleAlwaysUse24HourFormatChanged() {}.WidgetsBindingObserver(packages/flutter/lib/src/widgets/binding.dart):void didChangeAlwaysUse24HourFormat() {}.WidgetsBinding(packages/flutter/lib/src/widgets/binding.dart):handleAlwaysUse24HourFormatChanged()to dispatchobserver.didChangeAlwaysUse24HourFormat()to all registered observers.MediaQuery(packages/flutter/lib/src/widgets/media_query.dart):_MediaQueryFromViewState, implementeddidChangeAlwaysUse24HourFormat()to trigger_updateData()when root view's format changes, causing widgets depending onMediaQuery.alwaysUse24HourFormatOf(context)to rebuild with the updated preference.MediaQueryData.fromViewto listWidgetsBindingObserver.didChangeAlwaysUse24HourFormatanddart:ui.PlatformDispatcher.onAlwaysUse24HourFormatChanged.TestPlatformDispatcher(packages/flutter_test/lib/src/window.dart):onAlwaysUse24HourFormatChangedgetter/setter.alwaysUse24HourFormatTestValueandclearAlwaysUse24HourTestValueto invokeonAlwaysUse24HourFormatChanged.Unit Tests:
packages/flutter/test/widgets/binding_test.dart: Added testdidChangeAlwaysUse24HourFormatverifying observer dispatch and error handling.packages/flutter/test/widgets/media_query_test.dart: Added test verifyingMediaQuery.fromViewupdates whenalwaysUse24HourFormatchanges at runtime.packages/flutter_test/test/platform_dispatcher_test.dart: Added test verifyingTestPlatformDispatcher.alwaysUse24HourFormatTestValuetriggersWidgetsBindingObserver.didChangeAlwaysUse24HourFormat.