Skip to content

Instantly share code, notes, and snippets.

@9jaswag
Last active January 4, 2019 18:37
Show Gist options
  • Save 9jaswag/00a8d1e47bb9c8299d1713698ff9993f to your computer and use it in GitHub Desktop.
Save 9jaswag/00a8d1e47bb9c8299d1713698ff9993f to your computer and use it in GitHub Desktop.
counter bloc demo
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