【发布时间】:2019-12-06 17:51:38
【问题描述】:
我正在开发一个 Flutter 应用程序,在我的 Main 路由中,我有一个 Grid List,其中填充了由数据库检索的元素。
当 Grid 为空时,我想布局 Text() 消息,或类似的东西,
永久。
我用
list() {
return Container(
child: FutureBuilder(
future: pets,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == null) {
return emptyGrid();
}
else
return imageGrid(snapshot.data);
},
),
);
}
emptyGrid 在哪里
Container emptyGrid() {
return Container(
child: Center(
child: Column(
children: <Widget>[
Text("No Data Found")
],
),
),
);
}
问题是,emptyGrid 布局正确,但之后立即消失。
【问题讨论】:
-
听起来您的数据库正在返回数据。你打印出快照的值了吗?
-
你必须在
Widget build方法中这样做 -
@EricDuffett 我打印了。我的数据库是空的。 “没有数据”的布局,但只有一秒钟