Repository navigation
Add PlatformDispatcher.onAlwaysUse24HourFormatChanged callback - #194670
auto-submit[bot] merged 18 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request adds support for handling platform configuration changes, such as 24-hour format updates, by registering a callback on the PlatformDispatcher and propagating it through WidgetsBindingObserver to update MediaQuery dynamically. Feedback points out an unresolved documentation reference to alwaysUse24HourFormat in RendererBinding, suggesting it should be qualified as PlatformDispatcher.alwaysUse24HourFormat to resolve correctly.
|
Addressed doc reference review feedback in commit 00c9f72:
|
|
@googlebot I signed it! |
00c9f72 to
04b3df8
Compare
|
@googlebot I signed it! |
04b3df8 to
415849f
Compare
chunhtai
left a comment
There was a problem hiding this comment.
LGTM, just minor comment on the doc
415849f to
4e2375a
Compare
|
Hi, is this ready for another review? If yes, please remember to request a review so this goes back in the review queue. |
|
@victorsanni Yes, it is ready for review! The doc comment feedback from @chunhtai has been addressed in commit 4e2375a. Thanks! |
| /// | ||
| /// This method exposes notifications from | ||
| /// [dart:ui.PlatformDispatcher.onPlatformConfigurationChanged]. | ||
| void didChangePlatformConfiguration() {} |
There was a problem hiding this comment.
actually looking into the code closer, most of the property platform configuration is exposed individually in widgetbindingObserver.
I think we should directly expose the alwaysUse24HourFormat to something like
didChange24HourFormatThis will make it clear on what property has changed.
There was a problem hiding this comment.
that way, we don't need to worry about people not knowing what actually changed if we exposed didChangePlatformConfiguration directly
| super.handlePlatformConfigurationChanged(); | ||
| for (final observer in List<WidgetsBindingObserver>.of(_observers)) { | ||
| try { | ||
| observer.didChange24HourFormat(); |
There was a problem hiding this comment.
This doesn't look right, handlePlatformConfigurationChanged will be called when any of the configuration change. so even if the alwaysUse24HourFormat didn't change, the observer may still be notified.
There was a problem hiding this comment.
Great catch! We've added value-diff tracking via _alwaysUse24HourFormat in WidgetsBinding. Now handlePlatformConfigurationChanged checks if (_alwaysUse24HourFormat == currentAlwaysUse24HourFormat) return;, ensuring WidgetsBindingObserver.didChange24HourFormat() is strictly only dispatched when alwaysUse24HourFormat actually changes and not for other unrelated configuration updates.
Updated in commit 85de8fb with unit tests verifying that invoking handlePlatformConfigurationChanged() without an alwaysUse24HourFormat change does not notify observers.
| ..onTextScaleFactorChanged = handleTextScaleFactorChanged | ||
| ..onPlatformBrightnessChanged = handlePlatformBrightnessChanged; | ||
| ..onPlatformBrightnessChanged = handlePlatformBrightnessChanged | ||
| ..onPlatformConfigurationChanged = handlePlatformConfigurationChanged; |
There was a problem hiding this comment.
We should create a new API in platformdispatcher for 24hourformat just like onplatformbirightnessChanged
There was a problem hiding this comment.
Agreed! Having a dedicated onAlwaysUse24HourFormatChanged callback in PlatformDispatcher (matching onPlatformBrightnessChanged, onTextScaleFactorChanged, etc.) would be the cleanest long-term API on the engine side.
Since PlatformDispatcher lives in dart:ui (flutter/engine) and currently only dispatches onPlatformConfigurationChanged for 24-hour format updates (see also foundation/debug.dart:606), we've implemented the value-diff guard in WidgetsBinding (commit 85de8fb) so the framework never dispatches false notifications when other configuration changes occur. Would you like us to also open an engine PR for onAlwaysUse24HourFormatChanged?
There was a problem hiding this comment.
yes, we should do that, and also you can do this in the same pr
There was a problem hiding this comment.
Done in commit 4c056b8!
- Implemented onAlwaysUse24HourFormatChanged in PlatformDispatcher (both native dart:ui and web_ui).
- Registered handleAlwaysUse24HourFormatChanged in RendererBinding to directly observe the new callback.
- Updated WidgetsBinding to dispatch didChange24HourFormat to observers via the dedicated handler, eliminating the manual value-diffing workaround.
- Updated TestPlatformDispatcher and added unit tests in ui_test.dart, window_test.dart, �inding_test.dart, and platform_dispatcher_test.dart.
Thanks for the guidance! Ready for re-review.
Avoid notifying WidgetsBindingObserver.didChange24HourFormat when handlePlatformConfigurationChanged is triggered by unrelated platform configuration changes. Track _alwaysUse24HourFormat in WidgetsBinding and add unit tests to verify.
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
autosubmit label was removed for flutter/flutter/194670, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Hi @chunhtai and @victorsanni, All engine, web, and framework widget tests are passing cleanly across platforms, and Skia Gold has 0 untriaged images. The single failure in Could someone please trigger a rerun of this job on the dashboard and re-apply the |
Part of #194637
Pre-launch Checklist
///).Description
This PR introduces the engine API foundation for tracking platform 24-hour time format changes at runtime (split from the original full-stack PR per review feedback).
Changes
dart:ui.PlatformDispatcher:onAlwaysUse24HourFormatChangedcallback getter, setter, and zone tracking._updateUserSettingsDatato invokeonAlwaysUse24HourFormatChangedwheneveralwaysUse24HourFormatchanges.alwaysUse24HourFormatreferencing the new callback.lib/web_ui):onAlwaysUse24HourFormatChangedtoPlatformDispatcherinterface andEnginePlatformDispatcherimplementation.invokeOnAlwaysUse24HourFormatChanged()with zone preservation.platform_dispatcher_test.dartverifying callback invocation and zone preservation with per-test isolated dispatcher.packages/flutter):_debugNotifyViewMetricsOverrideChangedindebug.dartto forwardonAlwaysUse24HourFormatChanged.debug.dartto reflect thatalwaysUse24HourFormatnow announces throughonAlwaysUse24HourFormatChanged._DebugViewMetricsPlatformDispatcherand tests indebug_view_metrics_override_test.dart.engine/src/flutter/lib/ui/fixtures/ui_test.dartverifying thatonAlwaysUse24HourFormatChangedis invoked only whenalwaysUse24HourFormatchanges, and remains unaffected by unrelated settings. Cleaned up dispatcher callback at test completion.Note: Framework layer integration (
WidgetsBindingObserver.didChangeAlwaysUse24HourFormatandMediaQueryupdates) will follow in Part 2 once this engine API lands.