I wrote code like this:
Container(
height: 250,
child: StreamBuilder(
stream: db.collection("DebrisPeoples").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("yükleniyor");
} else {
final List<DebrisPeopleModel> data = snapshot.data!.docs
.map((e) => DebrisPeopleModel.fromDocument(e))
.toList();
inspect(data);
/*
OUTPUT:
[0]: DebrisPeopleModel
[1]: DebrisPeopleModel
[2]: DebrisPeopleModel
[3]: DebrisPeopleModel
[4]: DebrisPeopleModel
[5]: DebrisPeopleModel
*/
for (var item in data)
return Card(
child: ListTile(
title: Text(item.nameSurname.toString()),
),
);
}
return Container();
},
),
),
When I print it to the console, data shows up, but when I project it to the screen, only one item of data appears. Why could this be?
2
Answers
Wrap the
Card
with a ListView.builder instead of using thefor loop
.Try to return all cards instead of single item like