flutter - 没有为类型“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 的新手。这是我正在关注的一些项目教程。但是项目中使用的颤振版本已被弃用。所以我正在升级它并遇到了这个问题。以前的版本似乎没有这个问题。有人可以帮忙吗?
解决方案
data
DocumentSnapshot上的属性是一种返回文档快照内容的方法。您需要先执行它,然后才能访问 Map 的属性。
currentDocument.data().containsKey('username')
推荐阅读
- android - ViewPager 的适配器
- angular - 在角度中使用 FormArray
- java - 巴拿马:填充并不能防止虚假分享
- r - 如何在数据框列表上 lapply() 公式。或如何在数据帧列表上执行 kruskal.test()
- javascript - 如何在小 div 中创建一个大的 div 列表?
- rest - 电报:没有用 answerInlineQuery 发送答案
- javascript - 古腾堡:如何在古腾堡编辑器(java 脚本文件)中获取帖子视图计数
- magento2 - Magento-2.4.2 购物车视图抛出错误
- python - 工作簿保存失败,不知道为什么
- html - 使背景图像前面的黑色层不透明度为0.5