Skip to content

Instantly share code, notes, and snippets.

@yakubenko
Last active March 9, 2019 14:07
Show Gist options
  • Save yakubenko/e40c25ec023e0e59048211fa1bbfbfc5 to your computer and use it in GitHub Desktop.
Save yakubenko/e40c25ec023e0e59048211fa1bbfbfc5 to your computer and use it in GitHub Desktop.
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