[3.0.7] `setLocale` not updating `savedLocale`
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.
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.
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.
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 :)
Turnout its not that hard to change my package to a independent version.
Here is my experimental package if you are interested. @Nashev