languageSwitcherProvider top-level property
Provider that manages locale state with persistence using JetStorage
This provider combines Riverpod state management with local storage persistence to maintain the user's language preference across app restarts.
Usage example:
// Watch the current locale
final currentLocale = ref.watch(languageSwitcherProvider);
// Change the locale
ref.read(languageSwitcherProvider.notifier).changeLocale(const Locale('ar'));
// Access in widgets
Text('Current language: ${currentLocale.languageCode}');
The provider automatically:
- Loads the saved locale on initialization
- Validates that the locale is supported
- Persists changes to local storage
- Notifies listeners when the locale changes
Implementation
final languageSwitcherProvider =
NotifierProvider<LanguageSwitcherNotifier, Locale>(
LanguageSwitcherNotifier.new,
);