2021年1月29日星期五

Creating Stream for StreamBuilder with Firestore

I'm have created a Stream that it working inside StreamBuilder, but I have to pass some parameters to my Stream, this parameters are in a dart file which only has functions. I'm attempting to create the same code that was working, but passing the user uid.
This is what I attempted:

Stream<QuerySnapshot> main_page_stream() async*{      final FirebaseUser user = await _auth.currentUser();        Stream stream = Firestore.instance.collection('user_data').      document(user.uid).collection('Buttons').snapshots();        await for(var event in stream) {        yield event.documents;      }    }  

I get the following error:

Exception has occurred.  NoSuchMethodError (NoSuchMethodError: Class 'QuerySnapshot' has no instance getter 'snapshot'.  Receiver: Instance of 'QuerySnapshot'  Tried calling: snapshot)  

This isn't working on the home page:

StreamBuilder(          stream: _auth.main_page_stream(),          builder: (context, snapshot) {            if (snapshot.hasError){              return Container(color: Colors.red);            }            if (!snapshot.hasData){              print(snapshot.data);              return Center(child: CircularProgressIndicator());            }            if (snapshot.hasData){              var screenSize = MediaQuery.of(context).size.width;              return Stack(                children: [  

this was working:

stream: Firestore.instance.collection('user_data').document('sdsajnd82173812').collection('Buttons').snapshots(),  
https://stackoverflow.com/questions/65940218/creating-stream-for-streambuilder-with-firestore January 28, 2021 at 11:29PM

没有评论:

发表评论