简体   繁体   English

Class '列表<documentsnapshot> ' 在 Flutter 中没有实例方法 'call'</documentsnapshot>

[英]Class 'List<DocumentSnapshot>' has no instance method 'call' in Flutter

My firestore database looks something like this我的 firestore 数据库看起来像这样在此处输入图像描述

What I am trying to do is, I am making a Future list of all the documents with the same uid and then making a ListView using FutureBuilder.我想要做的是,我正在制作一个包含具有相同 uid 的所有文档的 Future 列表,然后使用 FutureBuilder 制作一个 ListView。

The part giving me the error is,给我错误的部分是,

body: FutureBuilder(
        future: listBuilder(),
        builder: (context, snapshot) {
          if(snapshot.hasData == null){
            return Container();
          }
          return ListView(
            padding: const EdgeInsets.only(top: 20.0),
            children: snapshot.data((data) => _buildListItem(context, data)).toList(),
          );
        },
      ),
Future listBuilder() async {
    final FirebaseUser user = await FirebaseAuth.instance.currentUser();
    final String uid = user.uid;
    List<DocumentSnapshot> list = [];
    Firestore.instance
        .collection('entries')
        .where("uid", isEqualTo: uid)
        .snapshots()
        .listen((data) => data.documents.forEach((doc) => list.add(doc)));

    print("------------------------------------------------------------------");
    return list;
  }
Widget _buildListItem(BuildContext context, DocumentSnapshot snapshot) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: InkWell(
        child: Row(
          children: <Widget>[
            Expanded(
              child: ListTile(
                leading: Text(
                  snapshot.data['type'],
                  style: TextStyle(
                    fontSize: 30,
                  ),
                ),
                title: Text(snapshot.data['description'],
                    style: TextStyle(
                      fontSize: 30,
                    )),
                subtitle: Text(snapshot.data['time'].toDate().toString(),
                    style: TextStyle(
                      fontSize: 15,
                    )),
                trailing: Text(snapshot.data['value'].toString(),
                    style: TextStyle(
                      fontSize: 25,
                    )),
              ), 
            )
          ],
        ),
      ),
    );
  }

Here is the error,这是错误,

Class 'List<DocumentSnapshot>' has no instance method 'call'.
Receiver: Instance(length:3) of '_GrowableList'
Tried calling: call(Closure: (dynamic) => Widget)

Thank you!谢谢!

Use the map method.使用map方法。

Like this像这样

     ...
children: snapshot.data.map((data)=>_buildListItem(context,data)).toList(),
     ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Class '_JsonQuerySnapshot' 没有实例方法 '[]' flutter - Class '_JsonQuerySnapshot' has no instance method '[]' flutter Flutter _JsonQuerySnapshot' 没有实例方法 '[]' - Flutter _JsonQuerySnapshot' has no instance method '[]' DocumentSnapshot 在将其作为类的命名参数传递时,在 flutter 中返回 null - DocumentSnapshot returns null in flutter while passing it as named argument of a class 未处理的异常:NoSuchMethodError:Class '_InternalLinkedHashMap<string, dynamic> ' 没有实例方法 'call'</string,> - Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'call' flutter 错误:Class '_InternalLinkedHashMap<string, dynamic> ' 没有实例方法 'toMap'。 接收者:_LinkedHashMap len:9 尝试调用:toMap()</string,> - flutter error : Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'toMap'. Receiver: _LinkedHashMap len:9 Tried calling: toMap() Flutter/Firebase - 列表<dynamic>没有实例 getter 'documents'</dynamic> - Flutter/Firebase - List<dynamic> has no instance getter 'documents' 如何作为方法的结果返回 DocumentSnapShot? - How to return a DocumentSnapShot as a result of a method? 在 Flutter 中将 Firestore DocumentSnapshot 转换为 Map - Convert Firestore DocumentSnapshot to Map in Flutter Class “QueryDocumentSnapshot”没有实例方法“[]”。 接收者:“QueryDocumentSnapshot”的实例尝试调用:[](“名称”) - Class 'QueryDocumentSnapshot' has no instance method '[]'. Receiver: Instance of 'QueryDocumentSnapshot' Tried calling: [] ("name") Flutter 云Firestore StreamBuilder<documentsnapshot> 错误</documentsnapshot> - Flutter cloud firestore StreamBuilder<DocumentSnapshot> error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM