Created
November 13, 2019 16:42
-
-
Save awaik/d9fa85d1de087fe3b3f5d04ff83b41c9 to your computer and use it in GitHub Desktop.
This file contains 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: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