firebase - 在颤振中添加if条件后,列表视图卡不起作用
问题描述
我的列表视图卡没有返回特定用户存储的所有项目,我想获取用户保存的所有产品
body: (products != null)
? ListView.builder(
itemCount: products.length,
itemBuilder: (context, index) {
if (products[index].ownerId == user.uid) {
return Card(
child: ListTile(
leading: Image.asset('graphics/broccoli.png'),
title: Text(products[index].name),
subtitle:
Text(products[index].price.toString() + " Rs"),
trailing: Icon(Icons.more_vert),
),
);
} else {
return null;
}
})
: Center(child: CircularProgressIndicator()));
解决方案
在该else
部分中,返回 aSizedBox()
而不是null
。
} else {
return const SizedBox();
}
这是因为任何小部件的构建方法或构建器函数必须始终返回 a Widget
,并且 anull
不是 a Widget
。
因此,每当我们想显示“无”或“空小部件”时,我们可以简单地返回一个SizedBox()
.
推荐阅读
- python - 如何获得 Jupyter Notebook 以查看打开它的环境中的模块?
- c# - 为什么我对 LastInsertedId 的调用没有返回预期值?
- python - 无法在 anaconda 提示符中创建进程
- android - 如何在 ItemTouchHelper 中显示图标?
- sql - Trouble calculating difference of results from nested sub queries and getting a syntax error
- r - 根据可编辑单元格用户输入更新闪亮的 DT
- node.js - Telegram:无法使用 Telegraf (NodeJs) 将消息/照片发送到频道
- c - 如何在解析过程中获取光标位置?
- javascript - TypeError:Order.find 不是函数
- amazon-web-services - 无法在 AWS EC2 Windows 实例中发出 API 请求