HydratedCubit<State> constructor
HydratedCubit<State> (
- State state, [
- Storage? storage
Specialized Cubit which handles initializing the Cubit state based on the persisted state. This allows state to be persisted across application restarts.
class CounterCubit extends HydratedCubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
void decrement() => emit(state - 1);
@override
int fromJson(Map<String, dynamic> json) => json['value'] as int;
@override
Map<String, int> toJson(int state) => {'value': state};
}
Implementation
HydratedCubit(State state, [Storage? storage]) : super(state) {
hydrate(storage: storage);
}