im getting this exception when i load the page, it appear on display for a moment but when list is loaded it disappears. errors reads out line 255, att line 255 i have a child: streambuilder i cannot figure out whats wrong
Expanded(
child: StreamBuilder(
stream: restaurants.where('status', isEqualTo: 'Approved').snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
return ListView(
children: snapshot.data!.docs.map((restaurants) {
return RestaurantCard(restaurants: restaurants,);
}).toList(),
);
},
),
)
You have to check for different statuses in StreamBuilder
, and only build the ListView
if there is data available:
StreamBuilder<DocumentSnapshot>(
stream: restaurants.where('status', isEqualTo: 'Approved').snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return const Center(
child: Text('Snapshot error'),
);
}
if (!snapshot.hasData) {
return const Center(
child: Text('Snapshot data missing'),
);
}
return ListView(
children: snapshot.data!.docs.map((restaurants) {
return RestaurantCard(restaurants: restaurants,);
}).toList(),
);
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.