简体   繁体   中英

Flutter How to cancel Streambuilder before auth.signOut?

I'm using Streambuilder to populate a Listview.builder with data from firestore. Everything works fine, but if the user decides to suddenly log out (auth.signOut) he's redirected to the login page, but I get a firestore warning in the console saying Listen for Query failed due to unsufficient permissions, which is understandable given the security rules on the db, which only allows reads/writes for authenticated users. I understand the Streambuilder closes automatically when the Widget tree where it lives gets destroyed, but how do I close it before auth.signOut is called in order to prevent this warning? Or can I just ignore the warning? Appreciate any lights.

You can just ignore it. As you mentioned, this is expected due to the authentication set, so it's no problem that this warning is showed in the console.

However, in case you want to close it, before the auth.signOut is called, as per this other question on the Community here , you can set your Stream as null before the method to sign out. The example used is the following one:

setState(() {
  _messageStream = null;
});

You can give it a try using something similar to the above code, to set your Stream as null, but just to reinforce, no problem in just ignoring the warning .

Let me know if the information helped you!

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