Skip to content

Conversation

@shivanuj13
Copy link
Contributor

@shivanuj13 shivanuj13 commented Nov 14, 2025

Recompute the resolved locale in LocalizationsResolver.update(...) and notify listeners
only when the resolved locale actually changes. Previously, updating WidgetsApp.supportedLocales
did not always propagate to the app locale because the resolver did not re-resolve and
notify listeners. This change fixes that bug and adds unit tests.

Fixes #117210

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@google-cla
Copy link

google-cla bot commented Nov 14, 2025

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.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 14, 2025
Copy link
Contributor

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

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 addresses a bug where changes to supportedLocales were not consistently propagating to the application's locale. The proposed solution correctly re-evaluates the resolved locale within LocalizationsResolver.update and triggers a notification only when the locale has actually changed, which is an efficient approach. The addition of unit tests is commendable, as they thoroughly verify both the bug fix and the conditional notification logic. The changes are well-implemented and align with the project's coding standards.

@shivanuj13
Copy link
Contributor Author

@victorsanni I have updated this PR with your suggested change.

@justinmc justinmc requested a review from victorsanni November 18, 2025 23:03
Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

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

Can you run dart format packages/flutter/test/widgets/localizations_test.dart to fix the Linux analyze failure?

WidgetsBinding.instance.platformDispatcher.locales,
_supportedLocales,
);
if (newLocale != _resolvedLocale) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can share code with didChangeLocales?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored the code to reuse this in didChangeLocals as well.

@victorsanni
Copy link
Contributor

Hi @shivanuj13, this is the failing customer test. Can you confirm if it is related to the changes in this PR?

@victorsanni
Copy link
Contributor

Can you confirm if it is related to the changes in this PR?

Actually scrap that, I've seen this same failure across unrelated PRs.

Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

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

I'm wondering if in widgets/app.dart we should only call update if any localization properties change, or if that is needless since it's mostly a parameter passthrough. Any thoughts?

@shivanuj13
Copy link
Contributor Author

shivanuj13 commented Nov 24, 2025

I went through widgets/app.dart and realized that we should only call update if any properties have changed. Therefore, we don't need to check them again (e.g., supportedLocales != _supportedLocales) inside LocalizationsResolver. I don't foresee any side effects from this change. Am i missing something?

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Flutter_LGTM
Thanks for contributing!

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 24, 2025
@victorsanni victorsanni moved this from In Progress to Done in Google Testing Queue Nov 24, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 24, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 24, 2025

autosubmit label was removed for flutter/flutter/178526, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@victorsanni
Copy link
Contributor

Same google testing failures as before... I'm surprised 74e8c5d passed google testing but the latest commit doesn't.

Comment on lines 812 to 813
_supportedLocales = supportedLocales;
_updateResolvedLocale(WidgetsBinding.instance.platformDispatcher.locales);
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 block from your previous commit will fix the Google testing:

Suggested change
_supportedLocales = supportedLocales;
_updateResolvedLocale(WidgetsBinding.instance.platformDispatcher.locales);
if (_supportedLocales != supportedLocales) {
_updateResolvedLocale(WidgetsBinding.instance.platformDispatcher.locales);
_supportedLocales = supportedLocales;
}

Can we add a test for this? The fact that Google testing triggers it and we don't is an indication we should probably test for it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think i have already aded a test that verify LocalizationsResolver does not notify if supportedLocales is unchanged. do we need to add a test for any other specific case?

@victorsanni victorsanni moved this from Done to In Progress in Google Testing Queue Nov 25, 2025
@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 25, 2025
@victorsanni victorsanni moved this from In Progress to Done in Google Testing Queue Nov 25, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Nov 26, 2025
Merged via the queue into flutter:master with commit 9655042 Nov 27, 2025
71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 27, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 27, 2025
flutter/flutter@7b98d50...022b155

2025-11-27 [email protected] Make tree green again by fixing lints (flutter/flutter#179186)
2025-11-26 [email protected] Add shared Darwin implementation for plugins (flutter/flutter#176495)
2025-11-26 [email protected] Fixed changing supportedLocales fails to update the locale (flutter/flutter#178526)
2025-11-26 [email protected] [ Tool ] Remove --no-sandbox when launching web apps on Chrome device (flutter/flutter#178670)
2025-11-26 [email protected] Build hooks: Don't require toolchain for unit tests (flutter/flutter#178954)
2025-11-26 [email protected] Fix a small typo in `HandlerCompat.java` docs (flutter/flutter#178595)
2025-11-26 [email protected] Roll Fuchsia Linux SDK from nzuAxCJGeJbkZCTkr... to _e9MNK4nfBOrERVP_... (flutter/flutter#179130)
2025-11-26 [email protected] Make sure that a CupertinoActivityIndicator doesn't crash in 0x0 envi… (flutter/flutter#178565)
2025-11-26 [email protected] [native assets] Bump minimum iOS version from 12 to 13 (flutter/flutter#179079)
2025-11-26 [email protected] Documents and fixes behavior when clipping background filter fragment shader (flutter/flutter#178940)
2025-11-26 [email protected] Replace the hardcoded link with an actual link tag in `PlatformChannel.java‎` docs (flutter/flutter#178588)
2025-11-26 [email protected] Roll Packages from cc3dca6 to 5d8d954 (5 revisions) (flutter/flutter#179140)
2025-11-26 [email protected] Add more templates that the UIScene migrator can match against (flutter/flutter#179044)
2025-11-26 [email protected] Remove deprecated activeColor in `dynamic_content_color.0.dart`‎ example (flutter/flutter#178961)
2025-11-26 [email protected] Remove deprecated `activeColor` in `decorated_sliver.1.dart‎` example (flutter/flutter#178959)
2025-11-26 [email protected] Small refactor in `PlayStoreDeferredComponentManager.java‎` (flutter/flutter#178586)
2025-11-26 [email protected] Roll Dart SDK from 9e605f706cdf to 1d8dc04bd1d7 (4 revisions) (flutter/flutter#179080)
2025-11-26 [email protected] Fix error when generating pt_BR localizations (flutter/flutter#175832)
2025-11-26 [email protected] Roll Fuchsia Test Scripts from JUeFbA8y0E-_pj-bg... to MHF-UAfO6sVKqSEYk... (flutter/flutter#179151)
2025-11-26 [email protected] Add flutter_lints to samples (flutter/flutter#179091)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
mboetger pushed a commit to mboetger/flutter that referenced this pull request Dec 2, 2025
…78526)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

Recompute the resolved locale in LocalizationsResolver.update(...) and
notify listeners
only when the resolved locale actually changes. Previously, updating
WidgetsApp.supportedLocales
did not always propagate to the app locale because the resolver did not
re-resolve and
notify listeners. This change fixes that bug and adds unit tests.

Fixes
[https://github.com/flutter/flutter/issues/117210](https://github.com/flutter/flutter/issues/117210)

## 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] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[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
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: anuj.kumar <[email protected]>
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…78526)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

Recompute the resolved locale in LocalizationsResolver.update(...) and
notify listeners
only when the resolved locale actually changes. Previously, updating
WidgetsApp.supportedLocales
did not always propagate to the app locale because the resolver did not
re-resolve and
notify listeners. This change fixes that bug and adds unit tests.

Fixes
[https://github.com/flutter/flutter/issues/117210](https://github.com/flutter/flutter/issues/117210)

## 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] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[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
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: anuj.kumar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

Development

Successfully merging this pull request may close these issues.

WidgetsApp: Changing supportedLocales fails to update the locale

4 participants