Skip to content

harisk92/blocx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BloCX

BLoC pattern implementation which simplifies process of writing BLoC and minimizes boilerplate which is needed to be written with traditional BLoC pattern implementation.

Usage

First we need to define actions and state

Actions

abstract CounterAction{

}

class IncrementCounterAction extends CounterAction{
}

State

class CounterState {
  int counter;

  CounterState() : this.counter = 0;
}

Then we implement BloC as follows

class CounterBloc extends Bloc<CounterAction, CounterState> {
  @override
  CounterState get initialState => CounterState();

  @override
  CounterState updateState(CounterState state, CounterAction action) {
    switch (action.runtimeType) {
      case IncrementCounterAction:
        return state..counter = state.counter + 1;
        break;
    }
    return state;
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages