Bnd10706
Bnd10706

Reputation: 2363

Populate only if data in Collection 1 matches data in Collection 2

I have 2 Collections. 1st Collection is set up like this.

firestore: SeriesCollection
{
seriesName: "Test Name"
seriesStartDate: 
seriesImage:
}

2nd Collection

firestore: SeriesAudioFiles
{
series: "Test Name"
audioFiles: 
speaker:
dateOfEvent:
}

here is my code

ExpandableContainer(
              expanded: expandFlag,
              child: ListView.builder(
                itemCount: snapshots.length,
                itemBuilder: (context, index) {
                  if (snapshots[index].data["series"] ==
                      snapshot[widget.index].data["seriesName"]) {
                    return ListTile(
                      leading: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            snapshots[index].data["month"],
                            style: TextStyle(
                                color: Colors.black.withOpacity(.5),
                                fontSize: 15),
                          ),
                          Text(
                            snapshots[index].data["day"],
                            style: TextStyle(
                                color: Colors.black.withOpacity(0.5),
                                fontSize: 30),
                          ),
                        ],
                      ),
                      title: Text(snapshots[index].data["sermonTitle"]),
                      subtitle:
                          Text(snapshots[index].data["sermonReference"]),
                      trailing: Icon(Icons.arrow_forward_ios),
                      onTap: () => passData(snapshots[index]),
                    );
                  }
                },
              ),)

What I am trying to do is list the SeriesAudioFiles ONLY if it matches the series name from both collections.

I probably have my firestore data set up wrong, but I am very new at this.

I have tried doing IF contains , but I cannot seem to get it to populate the data I actually need.

When I have been able to get data that actually does work, it is with a loop that pulls in the items several times.

Upvotes: 1

Views: 36

Answers (1)

LgFranco
LgFranco

Reputation: 1044

You can easily use the .where() method of the collection.
With that you can build a list with only the audios that you need:

audioListFromSerie = audioCollection.where((i) => i.series == serieList[iterationIndex].seriesName).toList();

Upvotes: 1

Related Questions