Created
June 20, 2018 16:48
-
-
Save marcmo/fbec8e580cac64f52a76ebaebc062c86 to your computer and use it in GitHub Desktop.
https://stackoverflow.com/questions/50951045/how-can-i-populate-a-stream-with-a-value-from-a-future example
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
class A { | |
Subject<int> _stateSubject; | |
Stream<int> _state; | |
Stream<int> get state { | |
return _state; | |
} | |
final Stream<DocumentSnapshot> _visitorCount = | |
Firestore.instance.document('ServerData/serverStatus').snapshots(); | |
A() { | |
_stateSubject = new BehaviorSubject(seedValue: 0); | |
_state = _stateSubject.asBroadcastStream(); | |
Stream<int> fireStoreStream = Firestore.instance | |
.document('ServerData/serverStatus') | |
.snapshots() | |
.map((DocumentSnapshot doc) => | |
doc['activeUsers'] as int); // your firestore query here | |
fireStoreStream.listen((int value) { | |
_stateSubject.add(value); // push your new value | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment