firebase - 参数类型'列表' 不能分配给参数类型 'List
问题描述
我正在尝试使用从 firebase 查询的数据构建列表视图。但是我有一个错误'参数类型'List <CommentData>'不能分配给参数类型'List<Widget>'代码如下
Widget buildComments() {
if (this.didFetchComments == false) {
return FutureBuilder<List<CommentData>>(
future: commentService.getComments(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Container(
alignment: FractionalOffset.center,
child: CircularProgressIndicator());
this.didFetchComments = true;
this.fetchedComments = snapshot.data;
return ListView(
children: snapshot.data, // where i'm having error
);
});
} else {
return ListView(children: this.fetchedComments);
}
}
我该如何解决这个问题..
解决方案
ListView
期望 aList<Widgets>
但你正在通过List<CommentData>
您可以将您的修改ListView
为以下内容以纠正错误。
ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return Text(snapshot.data[index]['key']); //Any widget you want to use.
},
);
推荐阅读
- android - 是否可以在我们的应用程序中使用电子邮件和密码查看 Firebase 登录用户的密码
- mysql - 表不存在
- angular - 在角度材料模态中自动刷新 iframe src
- crystal-reports - 如何从 Crystal Report 中的两个汇总组中获取差异?
- asynchronous - 如何在 dart (Flutter) 中使用 Future 和 .then() 转换这个简单的 async,await 格式化代码?
- mysql - 尝试更新不存在的记录时,MySql 不会抛出错误
- json - 使用 mongoimport 将许多 JSON 文件导入 MongoDB
- docker - Kubernetes 无法从 docker hub 存储库中提取图像
- windows - Docker Desktop 混合模式不再起作用
- neo4j - 查找通过 2 个关系连接到至少 2 个相同节点但中间节点不同的节点