【问题标题】:How can I display a firebase field into a listview in flutter如何在颤动中将 Firebase 字段显示到列表视图中
【发布时间】:2021-02-22 16:11:42
【问题描述】:

这些天我一直在努力编写 Flutter 代码,但我还是个新手。

我一直在尝试在列表视图上显示查询快照并将其显示在我的屏幕上。

为此,我有这个 API 调用可以帮助我获取我的 Firebase 字段中存在的所有订单:

    Future fetchOrders() async {
    QuerySnapshot qn = await firestoreInstance
        .collection('requests')
        .where('status',isEqualTo: 'open')
        .get();
    return qn.docs;
  }

而且我的小部件构建看起来像这样:

       @override
  Widget build(BuildContext context) {

    return Container(
      child: FutureBuilder(
          future: fetchOrders(),
          // ignore: non_constant_identifier_names
          builder: (_,snapshot){
        if(snapshot.connectionState == ConnectionState.waiting){
          return Center(
            child: Text("Loading ...")
          );
        } else{
          return ListView.builder(
            itemCount: snapshot.data.length,
            itemBuilder: (_, index){
            return ListTile(
              title: Text(snapshot.data[index].data["start"]),

            );
              });
        }
      }),
    );
  }

我的数据如下所示:

最后,我遇到了这个错误,但我不确定我是否正确:

The following NoSuchMethodError was thrown building:
Closure call with mismatched arguments: function '[]'
Receiver: Closure: () => Map<String, dynamic> from Function 'data':.
Tried calling: []("start")
Found: []() => Map<String, dynamic>

如果这个问题已经得到解答,我很抱歉。 谢谢:)!

【问题讨论】:

    标签: android ios firebase flutter


    【解决方案1】:

    您在ListTile 中写了太多次data

    改变这个

     Text(snapshot.data[index].data["start"])
    

    到这里

    Text(snapshot.data[index]["start"]
    

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      相关资源
      最近更新 更多