Issue
I already know if I want to use stream listen in method
to a snapshot so i need to use StreamSubscription
then dispose it using .cancel();
but what if use streamBuilder
under build method to get data from fisrstore
, do i need to dispose it too if yes HOW ?.. or it will be disposed it self when I press back bottom ?
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseFirestore.instance.collection("users").doc(widget.userId).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return circulearProgress();
}
Solution
The StreamBuilder
automatically manages the lifecycle of the underlying stream you pass it. You don't need to do anything for that yourself here, it will auto-close the stream (and remove the listener from Firestore) when the widget disappears from the UI that your build
method returns.
Also see:
Answered By - Frank van Puffelen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.