我有Futurebuilder来显示服务器中的数据。一切都很好,如果数据为空,我可以显示我的数据并显示图标。
return FutureBuilder<List<Mosque>>(
future: api.getMahasiswa(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
case ConnectionState.active:
return MyWidgetMain.wLoadingIndicator();
break;
default:
if (!snapshot.hasData)
return MyWidgetMain.wDataNotFound(); <<<<
else
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return ListMosque(
id: snapshot.data[index].id ?? "",
nrp: snapshot.data[index].nrp ?? "",
nama: snapshot.data[index].nama ?? "",
email: snapshot.data[index].email ?? "",
jurusan: snapshot.data[index].jurusan ?? "",
image: snapshot.data[index].image ?? "",
);
},
);
}
},
);
但是问题是,示例我有一些数据并将其删除,如果数据为空,我的Futurebuilder不会更新。
您能帮我吗?
谢谢
答案 0 :(得分:0)
**check data length first. if data length is null then you can show no data found image**
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
else if (snapshot.data != null) {
int l = snapshot.data.documents.length;
if (l == 0)
return Center(child: Image.asset("images/nodatafound.jpg"));
}