Skip to content

Add PlatformDispatcher.onAlwaysUse24HourFormatChanged callback - #194670

Merged
auto-submit[bot] merged 18 commits into
flutter:masterfrom
prasad2512:fix/issue-194637-refresh-always-use-24-hour
Nov 6, 2026
Merged

auto-submit[bot] merged 18 commits into
flutter:masterfrom
prasad2512:fix/issue-194637-refresh-always-use-24-hour

Conversation

@prasad2512

@prasad2512 prasad2512 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Part of #194637

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

  1. dart:ui.PlatformDispatcher:
    • Added onAlwaysUse24HourFormatChanged callback getter, setter, and zone tracking.
    • Updated _updateUserSettingsData to invoke onAlwaysUse24HourFormatChanged whenever alwaysUse24HourFormat changes.
    • Added documentation comments to alwaysUse24HourFormat referencing the new callback.
  2. Web Engine (lib/web_ui):
    • Added onAlwaysUse24HourFormatChanged to PlatformDispatcher interface and EnginePlatformDispatcher implementation.
    • Implemented invokeOnAlwaysUse24HourFormatChanged() with zone preservation.
    • Added unit tests in platform_dispatcher_test.dart verifying callback invocation and zone preservation with per-test isolated dispatcher.
  3. Framework Debug Overrides (packages/flutter):
    • Updated _debugNotifyViewMetricsOverrideChanged in debug.dart to forward onAlwaysUse24HourFormatChanged.
    • Updated comments in debug.dart to reflect that alwaysUse24HourFormat now announces through onAlwaysUse24HourFormatChanged.
    • Updated _DebugViewMetricsPlatformDispatcher and tests in debug_view_metrics_override_test.dart.
  4. Engine Unit Tests:
    • Added unit test in engine/src/flutter/lib/ui/fixtures/ui_test.dart verifying that onAlwaysUse24HourFormatChanged is invoked only when alwaysUse24HourFormat changes, and remains unaffected by unrelated settings. Cleaned up dispatcher callback at test completion.

Note: Framework layer integration (WidgetsBindingObserver.didChangeAlwaysUse24HourFormat and MediaQuery updates) will follow in Part 2 once this engine API lands.

@github-actions github-actions Bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Oct 18, 2026
@google-cla

google-cla Bot commented Oct 18, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@prasad2512

Copy link
Copy Markdown
Contributor Author

Addressed doc reference review feedback in commit 00c9f72:

  • Qualified [PlatformDispatcher.alwaysUse24HourFormat] in packages/flutter/lib/src/rendering/binding.dart so it resolves properly in generated dartdoc.

@prasad2512

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@prasad2512
prasad2512 force-pushed the fix/issue-194637-refresh-always-use-24-hour branch from 00c9f72 to 04b3df8 Compare October 19, 2026 17:47
@prasad2512

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@prasad2512
prasad2512 force-pushed the fix/issue-194637-refresh-always-use-24-hour branch from 04b3df8 to 415849f Compare October 19, 2026 17:49
chunhtai
chunhtai previously approved these changes Oct 26, 2026

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just minor comment on the doc

@victorsanni victorsanni added the CICD Run CI/CD label Oct 27, 2026
@prasad2512
prasad2512 force-pushed the fix/issue-194637-refresh-always-use-24-hour branch from 415849f to 4e2375a Compare October 27, 2026 09:07
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 27, 2026
@victorsanni

Copy link
Copy Markdown
Contributor

Hi, is this ready for another review? If yes, please remember to request a review so this goes back in the review queue.

@prasad2512

Copy link
Copy Markdown
Contributor Author

@victorsanni Yes, it is ready for review! The doc comment feedback from @chunhtai has been addressed in commit 4e2375a. Thanks!

@prasad2512
prasad2512 requested a review from chunhtai October 27, 2026 17:28
///
/// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onPlatformConfigurationChanged].
void didChangePlatformConfiguration() {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

didChange24HourFormat

This will make it clear on what property has changed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that way, we don't need to worry about people not knowing what actually changed if we exposed didChangePlatformConfiguration directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @chunhtai! That makes total sense and fits the existing WidgetsBindingObserver pattern much better. Updated to didChange24HourFormat in commit 0d17efa, along with updated docs, MediaQuery observer callback, and test cases.

@prasad2512
prasad2512 requested a review from chunhtai October 28, 2026 01:51
super.handlePlatformConfigurationChanged();
for (final observer in List<WidgetsBindingObserver>.of(_observers)) {
try {
observer.didChange24HourFormat();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@prasad2512 prasad2512 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should create a new API in platformdispatcher for 24hourformat just like onplatformbirightnessChanged

@prasad2512 prasad2512 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, we should do that, and also you can do this in the same pr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
@prasad2512
prasad2512 requested a review from chunhtai October 29, 2026 05:09
@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Oct 29, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Nov 5, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 5, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Nov 5, 2026
@flutter-dashboard

Copy link
Copy Markdown

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #194670 at sha 9306f3c

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Nov 5, 2026

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 6, 2026
@victorsanni victorsanni added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Nov 6, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2026
@auto-submit

auto-submit Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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.

@prasad2512

Copy link
Copy Markdown
Contributor Author

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 Mac mac_ios_debug_unopt_sim_arm64 is due to the known flaky test tracked in #194252 (-[FlutterViewControllerTest testViewWillTransitionToSize_DoesDelayEngineCallIfNonZeroDuration]).

Could someone please trigger a rerun of this job on the dashboard and re-apply the autosubmit label? Thank you!

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 6, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Nov 6, 2026

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 6, 2026
Merged via the queue into flutter:master with commit fabacd6 Nov 6, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically team-web Owned by Web platform team will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants