'How can i firestore stream snapsnot pause
I have a structure made up of tabs. I'm listening which tab you're in. I am using AutomaticKeepAliveClientMixin in tabs
late StreamSubscription _subscription;
@override
void initState() {
super.initState();
_subscription = FirebaseFirestore.instance
.collection('users')
.doc(id)
.snapshots().listen((DocumentSnapshot snapshot) => _onUpdate(snapshot));
widget.tab?.addListener(_tabListener);
}
@override
void dispose() {
_subscription.cancel();
widget.tab?.removeListener(_tabListener);
super.dispose();
}
_tabListener () {
if(widget.tab?.page == 0.0) {
if(_subscription.isPaused) {
_subscription.resume();
}
} else {
_subscription.pause();
}
}
No problem so far, it stops listening and picks up where it left off, but when it starts again it brings all the changes that happened when it stopped.
Keeps sending snapshot changes constantly in the background.
I want the stream to stop completely when the tab changes, and start over when it comes to tab, how can I do that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
