简体   繁体   中英

Flutter Firestore listen on Stream

I am using this code to listen on document changes:

Stream stream = db.doc(docRef.path).snapshots();

But I can't find a way to unsubscribe this listener from Firebase. I checked theStream class. Is this happening by default if I close the app? I found examples for this in other languages here but I can't figure out how to do this in dart.

Any advice? Thanks a lot!

You don't unsubscribe from Stream . You unsubscribe from StreamSubscription using the cancel() method.

So first start listening to your stream using .listen() on the stream, this will return you StreamSubscription which you can then cancel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM