restart method
Restarts the app with a new session key.
This method triggers a complete app restart by:
- Calling the onSetup callback with
reset: true
- Creating a new RestartState with the provided or auto-generated
appSessionKey
- Notifying listeners to rebuild the widget tree
If appSessionKey
is not provided, a timestamp-based key will be
automatically generated using DateTime.now().millisecondsSinceEpoch
.
Common patterns for custom session keys:
- Timestamp-based keys:
Key('session_${DateTime.now().millisecondsSinceEpoch}')
- Random keys:
Key(Random().nextInt(10000).toString())
- UUID keys:
Key(Uuid().v4())
Examples:
// Auto-generated key
notifier.restart();
// Custom key
notifier.restart(Key('restart_${DateTime.now().millisecondsSinceEpoch}'));
Implementation
void restart([Key? appSessionKey]) {
onSetup(this, reset: true);
_state = RestartState(
appSessionKey ?? Key(DateTime.now().millisecondsSinceEpoch.toString()));
notifyListeners();
}