2
votes

So I have a nested collections and I would like to extract the data into a list but I can't seem to figure out how to extract it to a list. I can only extract the data once at a time and I am unable to put them into a list.

This is the logic - User(collection) -> Document(some document Id) -> a field of data that I all ArtShowClass.

General(collection) -> ShowDocument(some document ID) -> ShowCollection -> (some document ID) -> a field of datatype reference that stores a reference to that a users document reference.

This is a basic post from a user

This is what it looks like after I store the reference datatype

More explanation.

/User/y7qg9IwVcEeGGp47qgzVvL8u0ak1/Posts/2020-02-22 19:44:45.409573 /User/y7qg9IwVcEeGGp47qgzVvL8u0ak1/Posts/2020-02-23 02:03:14.119358

/GeneralList/Art Shows/Shows 1/2020-02-22 19:44:45.409573 -> This has a reference data type of /User/y7qg9IwVcEeGGp47qgzVvL8u0ak1/Posts/2020-02-22 19:44:45.409573

/GeneralList/Art Shows/Shows 1/2020-02-23 02:03:14.119358 -> This has a reference data type of /User/y7qg9IwVcEeGGp47qgzVvL8u0ak1/Posts/2020-02-23 02:03:14.119358

I was able to write code to get the data in a list view and print. But I don't exactly want that, I want to extract all the data into a list and then send it to a different widget.

This is what I did to print them as some kind of list

final CollectionReference exploreCollection = Firestore.instance.collection('GeneralList');

> Widget build(BuildContext context) {
>     User user = Provider.of<User>(context);
>     String sdfdsfdf;
>     var explorer = exploreCollection.document("Art Shows").collection("Shows 1").snapshots();
>     return StreamBuilder<QuerySnapshot>
>     (
>       stream: explorer,
>       builder: (context, snapshot){
>         if (!snapshot.hasData)
>           return Text("Loading data...", style: TextStyle(color: Colors.white),);
>         
>         return ListView(children: snapshot.data.documents.map((document)
>         {
>           DocumentReference documentReference = document.data['ref']; 
>           //Stream<ArtShowClass> sdfd = documentReference.snapshots().map(_showsHelperFromSnapShot);
>           return StreamBuilder<DocumentSnapshot>(
>             stream: documentReference.snapshots(),
>             builder: (context, snapshot) {
> 
>               if (!snapshot.hasData) return Text("Loading...");
>                 ArtShowClass sdfd = ArtShowClass(
>                   userHandle: snapshot.data['userHandle'] ?? '',
>                   artShowTitle: snapshot.data['artShowTitle'] ?? '',
>                   artistName: snapshot.data['artistName'] ?? '',
>                   artShowAddress: snapshot.data['artShowAddress'] ?? '',
>                   artShowDescription: snapshot.data['artShowDescription'] ?? '',
>                   artShowDate: snapshot.data['artShowDate'] ?? '',
>                   artShowTime: snapshot.data['artShowTime'] ?? '',
>                   websiteLink: snapshot.data['websiteLink'] ?? '',
>                   email: snapshot.data['email'] ?? '',
>                   phoneNumber: snapshot.data['phoneNumber'] ?? '',
>                   pictureName: snapshot.data['pictureName'] ?? '',
>                   genre: snapshot.data['genre'] ?? '',
>                   ticketAmount: snapshot.data['ticketAmount'] ?? 0
>                 );
>               sdfdsfdf = snapshot.data['email'];
>               return Text("${snapshot.data['email']}", style: TextStyle(color: Colors.red),);
>             },
>           );
>         }).toList());
>       },
>     );   }

Thanks for the help.

1

1 Answers

1
votes

There are some ways that you can return information from nested collections.

I have performed some search and I could find some nice posts on the Community that might help you - since each one of them are for a specific case, I believe you checking them, should provide you a better overview, since you know better your own structure. Both below questions are accepted and solved their problems, so I would recommend you to take a look at it.

Let me know if the information helped you!