Last active
March 9, 2019 14:07
-
-
Save yakubenko/e40c25ec023e0e59048211fa1bbfbfc5 to your computer and use it in GitHub Desktop.
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
import 'dart:async'; | |
class CounterBloc { | |
int _counter = 0; | |
final _stateController = StreamController<int>(); | |
// This one goes to the StreamBuilder | |
Stream<int> get counterStream => _stateController.stream; | |
// This is one of posible modificators | |
// I chose String for simplicity. We can pass a param of any type and the check it. | |
void modifyCounter(String direction) { | |
if (direction == 'up') { | |
_counter++; | |
} else { | |
_counter--; | |
} | |
// This causes the StreamBuilder to rerender itself | |
_stateController.sink.add(_counter); | |
} | |
void dispose() { | |
_stateController.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment