PersistedBloc<S> constructor
PersistedBloc<S> ({
- S? initialState,
- BlocMonitor monitor = const BlocEventsPrinter(),
- Object tag = 0,
- bool autoPersistence = false,
- bool recoverStateOnStart = false,
Implementation
PersistedBloc({
S? initialState,
BlocMonitor monitor = const BlocEventsPrinter(),
this.tag = 0,
bool autoPersistence = false,
bool recoverStateOnStart = false,
}) : _autoPersistence = autoPersistence,
_recoverStateOnStart = recoverStateOnStart,
super(
initialState:
(autoPersistence && recoverStateOnStart) ? null : initialState,
monitor: monitor,
) {
if (_autoPersistence && _recoverStateOnStart) {
persistenceService.get<S>('value').then((got) {
if (got == null) {
if (initialState != null) {
// if initialState is null then the bloc's is already set to busy
super.setState(initialState, event: 'initializing');
}
} else {
super.setState(got, event: 'recovered_state');
}
});
}
}