Widget BlogsList() {
return Container(
color: UniversalVariables.blackColor,
child: blogsStream != null
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
StreamBuilder(
stream: blogsStream,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data.documents.isEmpty) ;
return ListView.builder(
padding: EdgeInsets.symmetric(horizontal: 16),
itemCount: snapshot.data.documents.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return BlogsTile(
authorName: snapshot
.data.documents[index].data['authorName'],
title: snapshot.data.documents[index].data["title"],
description:
snapshot.data.documents[index].data['desc'],
imgUrl:
snapshot.data.documents[index].data['imgUrl'],
);
});
},
)
],
)
: Container(
alignment: Alignment.center,
child: CircularProgressIndicator(),
),
); }
我希望将其设为强制性。给红色屏幕并打开。我想解决这个问题。我正在使用Firebase提取数据。我在页面之间切换时遇到问题,但是无法解决我的错误。
答案 0 :(得分:1)
发生错误是在您的构建器中,无论ListView
是否为真,您都返回了snapshot.hasData
。
尝试
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data.documents.isEmpty){
return Center(child: Text("Loadin..."));
}
return ListView.builder(
padding: EdgeInsets.symmetric(horizontal: 16),
itemCount: snapshot.data.documents.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return BlogsTile(
authorName: snapshot.data.documents[index].data['authorName'],
title: snapshot.data.documents[index].data["title"],
description:snapshot.data.documents[index].data['desc'],
imgUrl:snapshot.data.documents[index].data['imgUrl'],
);
});
},