Reputation: 43
I have streamBuilder, when I go to the page with it for a split second there is an error about the zero return of the function, i.e. the data does not have time to load and the function returns null
if (customers != null) {
return StreamBuilder(
stream: customers,
//initialData: ,
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
if (snapshot.data != null) {
return ListView.builder(
itemCount: snapshot.data.documents.length,
padding: EdgeInsets.all(5.0),
itemBuilder: (context, i) {
return new ListTile(
title:
Column(mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(snapshot.data.documents[i].data['pickedDay'],),
Text(snapshot.data.documents[i].data['pickedTime']),
Text(snapshot.data.documents[i].data['service']),
Text(snapshot.data.documents[i].data['phoneNumber']),
Divider(height: 10, color: primaryColor2),
],),
},
);
},
);
}
}
// }
},
);
} else {
return new CircularProgressIndicator();
}
}>
How can i fix this?
Upvotes: 2
Views: 972
Reputation: 2460
Your builder is not returning data when snapshot.hasData
is false. That's why you see that error.
You should return something. It can be just an empty container or a loading spinner. Something like this:
if (snapshot.hasData || snapshot.data != null) {
//your current code
}else{
return Container()
}
Upvotes: 4