Skip to content

Instantly share code, notes, and snippets.

@awaik
Created November 13, 2019 16:42
Show Gist options
  • Save awaik/d9fa85d1de087fe3b3f5d04ff83b41c9 to your computer and use it in GitHub Desktop.
Save awaik/d9fa85d1de087fe3b3f5d04ff83b41c9 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:rxdart/rxdart.dart';
class CounterBloc {
int _counter;
CounterBloc() {
_counter = 1;
_actionController.stream.listen(_increaseStream);
}
final _counterStream = BehaviorSubject<int>.seeded(1);
Stream get pressedCount => _counterStream.stream;
Sink get _addValue => _counterStream.sink;
StreamController _actionController = StreamController();
StreamSink get incrementCounter => _actionController.sink;
void _increaseStream(data) {
_counter += 1;
_addValue.add(_counter);
}
void dispose() {
_counterStream.close();
_actionController.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment