RestartNotifier class
A ChangeNotifier that manages app restart functionality.
This class provides a simple way to restart your Flutter app's widget tree by changing the session key, which forces Flutter to completely rebuild the widget hierarchy. This is useful for scenarios like user logout, theme changes, language switches, or complete app state resets.
Example usage:
final notifier = RestartNotifier(onSetup: (notifier, {reset}) async {
if (reset) {
// Clear app state
await clearUserData();
}
});
// Restart the app with auto-generated key
notifier.restart();
// Or restart with custom key
notifier.restart(Key('custom_session_key'));
- Inheritance
-
- Object
- ChangeNotifier
- RestartNotifier
Constructors
- RestartNotifier.new({required void onSetup(RestartNotifier notifier, {bool reset})})
- Creates a new restart notifier with the given setup callback.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- onSetup → void Function(RestartNotifier notifier, {bool reset})
-
Callback function called during initialization and restart.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → RestartBaseState
-
Gets the current restart state.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
restart(
[Key? appSessionKey]) → void - Restarts the app with a new session key.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited