Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to automatically sync the current locale with the system locale #21

Open
bratan opened this issue Nov 27, 2019 · 12 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@bratan
Copy link
Member

bratan commented Nov 27, 2019

Add an option to automatically sync the current locale with the system locale.

So when the system locale is changed, the current/app locale will be reloaded as well (if supported).

Reference: #20

@diegoveloper
Copy link

Can you detect the language change in localeResolutionCallback then rebuild the LocalizationProvider ?

@bratan
Copy link
Member Author

bratan commented Nov 30, 2019

There are some issues preventing this from working currently but yes, I think this will be the way to go.

@doc-rj-celltrak
Copy link

Thanks for the great package, we may be using it in our app. Is this enhancement still planned?

@kuhnroyal
Copy link

@bratan Can you elaborate on why the flutter_device_locale package is needed. The same functionality and the syncing is available in plain Flutter via WidgetsBinding.instance.addObserver(...) or am I missing something?

@bratan
Copy link
Member Author

bratan commented May 12, 2020

@kuhnroyal - Because of some iOS issues where different values for the current/selected locale are returned depending on the environment (debug/release) and device type simulator/real device.

So by using flutter_device_locale the real locale is always used regardless of the environment.

More info:
flutter/flutter#14128
#15

@kuhnroyal
Copy link

@bratan Thanks, Right I now remember this issue. I though this is solved by adding the correct plist entries tho.

@diegoveloper
Copy link

@bratan what about doing this

    final currentLocale = WidgetsBinding.instance.window.locale;
    final locale = currentLocale != null && currentLocale.countryCode != null
        ? currentLocale
        : Localizations.localeOf(context);

to avoid using flutter_device_locale , btw any progress on this issue? thanks for this great package!

@doc-rj-celltrak
Copy link

Hi @bratan is there any update on this issue? Thanks.

@bratan
Copy link
Member Author

bratan commented Aug 25, 2020

Hi, there is no update currently as I`m quite busy these days, probably in the near future.

@doc-rj-celltrak
Copy link

doc-rj-celltrak commented Aug 25, 2021

If anyone wants to implement this themselves, you can use a WidgetsBindingObserver and override didChangeLocales(). Do this with a StatefulWidget below LocalizedApp and above MaterialApp.

When a system locale change is detected, you can do something like this:

    Future<void> _didChangeLocales(
    BuildContext context,
    List<Locale>? locales,
  ) async {
    if (locales != null && locales.isNotEmpty &&
        locales.first != LocalizedApp.of(context).delegate.currentLocale) {
      if (Platform.isAndroid) {
        Restart.restartApp();
      }
    }
  }

In my case, I'm restarting the app natively for Android, due to problems trying to force-rebuild the entire widget tree. I'm using the restart_app plugin to do that.

@stale
Copy link

stale bot commented May 4, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label May 4, 2022
@stale stale bot closed this as completed May 11, 2022
@bratan bratan reopened this Nov 17, 2023
@bratan bratan removed the wontfix This will not be worked on label Nov 21, 2023
Copy link

stale bot commented Jan 20, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants