Skip to content

Instantly share code, notes, and snippets.

@marcmo
Created June 20, 2018 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcmo/fbec8e580cac64f52a76ebaebc062c86 to your computer and use it in GitHub Desktop.
Save marcmo/fbec8e580cac64f52a76ebaebc062c86 to your computer and use it in GitHub Desktop.
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