LanguageSwitcherNotifier class
State notifier that manages locale switching with persistence
This class handles:
- Loading saved locale preferences from storage
- Validating that locales are supported by the app
- Persisting locale changes to local storage
- Managing the current locale state
Example usage:
class MyWidget extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final notifier = ref.read(languageSwitcherProvider.notifier);
final currentLocale = ref.watch(languageSwitcherProvider);
return ElevatedButton(
onPressed: () => notifier.changeLocale(const Locale('ar')),
child: Text('Switch to Arabic'),
);
}
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- ref → Ref
-
The Ref associated with this notifier.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state ↔ Locale
-
The value currently exposed by this notifier.
getter/setter pairinherited
- stateOrNull → Locale?
-
The value currently exposed by this Notifier.
no setterinherited
Methods
-
build(
) → Locale -
Initialize a Notifier.
override
-
changeLocale(
Locale locale) → Future< void> - Change the current locale and persist the selection
-
listenSelf(
void listener(Locale? previous, Locale next), {void onError(Object error, StackTrace stackTrace)?}) → RemoveListener -
Listens to changes on the value exposed by this provider.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
runBuild(
) → void -
Executes Notifier.build.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
updateShouldNotify(
Locale previous, Locale next) → bool -
A method invoked when the state exposed by this Notifier changes.
It compares the previous and new value, and return whether listeners
should be notified.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited