简体   繁体   中英

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(),

The QuerySnapshot - event doesn't have a field snapshot . Instead you have to

yield event;

And for this the function return you the Stream<QuerySnapshot> .

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