'Flutter how to store sharepreferances value for localization in bloc
i have implemented localization with bloc pattern but now I wanna store the value of language in sharepreferences so that next time if the user already selected language it will skip select language flow and fetch it from local storage. this is my code for language state.
class LanguageState extends Equatable {
final Locale locale; const LanguageState({required this.locale}); factory LanguageState.initial() => const LanguageState(locale: Locale('en', 'US'));
LanguageState copyWith({required Locale locale}) => LanguageState(locale: locale);
@override // TODO: implement props List get props => [locale]; }
Solution 1:[1]
you can use this package for localization easylocalization
you can fetch current locale value like this
var currentLocale = EasyLocalization.of(context)?.locale ?? 'en';
& store the value like this in sharedpreference
await SharedPref.write("local_val", //your value);
& use it in your condition
If(local_val != null){
//do your navigation
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Taqi Tahmid Tanzil |
