Last active
March 9, 2019 14:07
-
-
Save yakubenko/e40c25ec023e0e59048211fa1bbfbfc5 to your computer and use it in GitHub Desktop.
Revisions
-
yakubenko revised this gist
Mar 9, 2019 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,19 @@ 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); } -
yakubenko created this gist
Mar 9, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import 'dart:async'; class CounterBloc { int _counter = 0; final _stateController = StreamController<int>(); Stream<int> get counterStream => _stateController.stream; void modifyCounter(String direction) { if (direction == 'up') { _counter++; } else { _counter--; } _stateController.sink.add(_counter); } void dispose() { _stateController.close(); } }