I suppose to show each item of my shopList in ListView, but I can't find out the reason why it keep showing the same record. Please help to solve this issue.
Here with the code, get data from firebase database.
databaseReference.once().then((DataSnapshot snapshot) {
Map<dynamic, dynamic> getMap = snapshot.value;
getMap.forEach((k, v) {
Map<dynamic, dynamic> f = v;
shop.key = k;
shop.shopName = f["ShopName"];
shop.tel = f["ShopTel"];
shop.address = f["ShopAddress"];
shop.thumbnail = f["Thumbnail"];
debugPrint(k);
shopList.add(shop);
debugPrint(shopList[shopList.length-1].shopName);
});
});
DebugPrint result:
- flutter: -LLySYDHHHx9WtCvKPrO
- flutter: shop1111
- flutter: -LLyXwR0nnAcx6_H4cYy
- flutter: shop2222
Here with the code for ListView:
child: Flexible(
child: new ListView.builder(
itemCount: shopList.length,
itemBuilder: (context, index) {
return new Card(
color: Colors.red,
//elevation: 2.0,
child: new ListTile(
title: new Text("Name: ${shopList[index].key}"),
),
);
}),
),
the result of simulator: