首页 > 解决方案 > 没有为类型“function”定义方法“containsKey”。我该如何解决?

问题描述

    var data = {
      'photoUrl': profileImageUrl,
      'age': age,
      'username': username,
    };
    //ref.setData(data, merge: true);
    ref.set(data);
    SetOptions(merge: true);
    final DocumentSnapshot currentDocument = await ref.get();
    return Utilizer.fromFirestore(currentDocument);
  }
 @override
  Future<bool> isProfileComplete(String uid) async {
    DocumentReference ref = fireStoreDb.collection(Paths.usersPath).doc(uid);
    final DocumentSnapshot currentDocument = await ref.get();

    return (currentDocument.exists &&
        
        currentDocument.data.containsKey('username') &&  //error here
        currentDocument.data.containsKey('age'));        //error here

我是 Flutter 和 OOP 的新手。这是我正在关注的一些项目教程。但是项目中使用的颤振版本已被弃用。所以我正在升级它并遇到了这个问题。以前的版本似乎没有这个问题。有人可以帮忙吗?

标签: flutterdartmaps

解决方案


dataDocumentSnapshot上的属性是一种返回文档快照内容的方法。您需要先执行它,然后才能访问 Map 的属性。

currentDocument.data().containsKey('username')

推荐阅读