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();
}
CodePudding user response:
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: