BaseState<T> class

Every state class must derived from BaseState<T> class. And it is mandatory to pass the state name and initialState.

Example:

class CounterModel {
 int count;
 bool isLoading;

 CounterModel({this.count, this.isLoading});

 copyWith({int count, bool isLoading}) {
   return CounterModel(
       count: count ?? this.count, isLoading: isLoading ?? this.isLoading);
 }

 CounterModel.init() : this(count: 10, isLoading: false);
}

class CounterState extends BaseState<CounterModel> {
 CounterState() : super(name: 'counter', initialState: CounterModel.init());

 Stream<CounterModel> mapActionToState(
     CounterModel state, Action action) async* {
   switch (action.type) {
     case ActionTypes.Inc:
       state.count++;
       yield state.copyWith(isLoading: false);
       break;
     case ActionTypes.Dec:
       state.count--;
       yield state.copyWith(isLoading: false);
       break;
     case ActionTypes.AsyncInc:
       yield state.copyWith(isLoading: true);
       yield await getCount(state.count);
       break;
     default:
       yield state;
   }
 }

 Future<CounterModel> getCount(int count) {
   return Future.delayed(Duration(milliseconds: 500),
       () => CounterModel(count: count + 1, isLoading: false));
 }
}

Constructors

BaseState({String name, T initialState })

Properties

initialState → T
final
name → String
final
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

mapActionToState(T state, Action action) → Stream<T>
This method should be invoked by sysytem passing current state and action. You should mutate the state based on action [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited