Last active
March 25, 2019 03:12
-
-
Save felangel/62a02c7a23c27ccd04cbdbe4deb8a9b1 to your computer and use it in GitHub Desktop.
[bloc_package] counter bloc w/ onTransition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum CounterEvent { increment, decrement } | |
class CounterBloc extends Bloc<CounterEvent, int> { | |
@override | |
int get initialState => 0; | |
@override | |
void onTransition(Transition<CounterEvent, int> transition) { | |
print(transition); | |
} | |
@override | |
Stream<int> mapEventToState(CounterEvent event) async* { | |
switch (event) { | |
case CounterEvent.decrement: | |
yield currentState - 1; | |
break; | |
case CounterEvent.increment: | |
yield currentState + 1; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment