Last active
January 4, 2019 18:37
-
-
Save 9jaswag/00a8d1e47bb9c8299d1713698ff9993f to your computer and use it in GitHub Desktop.
counter bloc demo
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 characters
import 'dart:async'; | |
import 'package:bloc_counter/counter_provider.dart'; | |
class CounterBloc { | |
final counterController = StreamController(); // create a StreamController | |
final CounterProvider provider = CounterProvider(); // create an instance of our CounterProvider | |
Stream get getCount => counterController.stream; // create a getter for our stream | |
void updateCount() { | |
provider.increaseCount(); // call the method to increase our count in the provider | |
counterController.sink.add(provider.count); // add the count to our sink | |
} | |
void dispose() { | |
counterController.close(); // close our StreamController | |
} | |
} | |
final bloc = CounterBloc(); // create an instance of the counter bloc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment