I have data from my firebase and to simplify my code I would like to return a loop of all elements. Here is my Streambuilder:
Column(
children: <Widget>[
Container(
height: 300,
width: double.infinity,
child: Image.network(
widget.image,
fit: BoxFit.cover,
),
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection(
'/towns/${widget.townId}/beacons/${widget.beaconId}/content')
.snapshots(),
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return CircularProgressIndicator();
final contents = snapshot.data.docs;
for (int i = 1; i <= 10; i++) {
return Column(
children: [
contents[1]['sectionTitle$i'].isNotEmpty
? buildSectionTitle(
context, contents[1]['sectionTitle$i'])
: Container(),
contents[1]['text$i'].isNotEmpty
? buildText(context, contents[1]['text$i'])
: Container(),
contents[1]['audio$i'].isNotEmpty
? Audio(contents[1]['audio$i'], key: UniqueKey())
: Container(),
contents[1]['image$i'].isNotEmpty
? buildImage(context, contents[1]['image$i'])
: Container(),
],
);
}
return Container();
}),
],
),
In my firebase, I have all the elements (sectionTitle1, sectionTitle2, etc.) are on the same document (here contents[1]). The problem is the Streambuild only returns the firsts elements of my loop. For example, if I start to i = 1, the loop will return sectionTitle1, text1, audio1 and image1 ; if I start to i = 3, the loop will return sectionTitle3, text3, audio3 and image3. How can I return everythings ?