Reputation: 185
I am getting an error with the streambuilder in flutter. I'm not sure why I get this error. Please help me out with this problem.
Widget _galleryGrid() {
return StreamBuilder(
stream: imageUrlsController.stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data!.length != 0) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return CachedNetworkImage(
imageUrl: snapshot.data![index],
fit: BoxFit.cover,
placeholder: (context, url) => Container(
alignment: Alignment.center,
child: CircularProgressIndicator()
)
);
}
);
} else {
return Center(child: Text('No images to display.'));
}
} else {
return Center(child: CircularProgressIndicator());
}
}
);
}
I have red underline indicating error in 3 parts in total
if (snapshot.data!.length != 0) {
itemCount: snapshot.data!.length,
imageUrl: snapshot.data![index]
Upvotes: 0
Views: 335
Reputation: 2272
Simply specify your snapshot type in builder of stream as:-
builder: (context, AsyncSnapshot<QuerySnaphot> snapshot) {
Upvotes: -1
Reputation: 329
OR
replace this with
if (snapshot.data!.isNotEmpty) {
Upvotes: 1