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

[3.0.7] setLocale not updating savedLocale #702

Open
hsynksahin opened this issue Aug 15, 2024 · 4 comments
Open

[3.0.7] setLocale not updating savedLocale #702

hsynksahin opened this issue Aug 15, 2024 · 4 comments

Comments

@hsynksahin
Copy link

I've written a language changing page. It is reading the saved locale when initializing and shows it.

When you select an other language and accept it it changes the locale of the page without any problem. But here is the thing...

If I open the language page againg Im seing that the selected language is not the one I've selected. It is the one the application started with. I've investigated the problem a little and find this:

for version 3.0.7
on easy_localization_controller.dart line 185

Future<void> _saveLocale(Locale? locale) async {
    if (!saveLocale) return;
    final preferences = await SharedPreferences.getInstance();
    await preferences.setString('locale', locale.toString());
    // There is no `_savedLocale = locale;` to update saved locale variable
    EasyLocalization.logger('Locale $locale saved');
  }

So in the and if you change the locale, the saved locale variable not being updated. There for we need to wait for the next application init for it the be updated.

@hsynksahin
Copy link
Author

hsynksahin commented Aug 15, 2024

And if saved method gonna be updated. May I request something ?

I want my Language changing page to be abel to choose system language. Which means when user choices that, the app will turn into device's language and delete the saved locale.

Can we make the setLocale's parameter nullable so when null, it will use the device (if not supported fallback) locale and delete saved locale. (Also will set _savedLocaleto null)

Note: For now I configured the package to not save my locale, and made my own saving logic.

Thanks for this very nice package tho.

@Nashev
Copy link

Nashev commented Aug 18, 2024

BTW, have You noticed about resetLocale() method?

And could You publish you locale selector as a reusable widget? May be even as PR to this library! I would like to have similar selector in my app on a settings screen.

@hsynksahin
Copy link
Author

Im already using resetLocale() since no other way changes the content of _savedLocale it is still not working. As I said writing my own saving method makes more sense for now.

As for the sharing that module, is something I'm intended to. But for now it uses many of my private libraries and a BLOC structure so its highly dependent for a shared library. I will rewrite the whole thing withot dependencies so maybe one day :)

@hsynksahin
Copy link
Author

Turnout its not that hard to change my package to a independent version.

Here is my experimental package if you are interested. @Nashev

Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants