Flutter 方法';containsKey';isn';t为类型';函数';。我怎样才能修好它? var数据={ “photoUrl”:profileImageUrl, “年龄”:年龄, “用户名”:用户名, }; //ref.setData(数据,合并:真); 参考集(数据); SetOptions(合并:true); final DocumentSnapshot currentDocument=等待参考get(); 从FireStore返回实用程序(currentDocument); } @凌驾 未来isProfileComplete(字符串uid)异步{ DocumentReference ref=fireStoreDb.collection(path.usersPath.doc(uid)); final DocumentSnapshot currentDocument=等待参考get(); 返回(currentDocument.exists)&& currentDocument.data.containsKey('username')&&//此处有错误 currentDocument.data.containsKey('age');//此处出错
我不熟悉颤振和OOP。这是我正在学习的一些项目教程。但是项目中使用的颤振版本已被弃用。因此,我在升级它时遇到了此问题。以前的版本似乎对此没有问题。有人可以帮助我吗Flutter 方法';containsKey';isn';t为类型';函数';。我怎样才能修好它? var数据={ “photoUrl”:profileImageUrl, “年龄”:年龄, “用户名”:用户名, }; //ref.setData(数据,合并:真); 参考集(数据); SetOptions(合并:true); final DocumentSnapshot currentDocument=等待参考get(); 从FireStore返回实用程序(currentDocument); } @凌驾 未来isProfileComplete(字符串uid)异步{ DocumentReference ref=fireStoreDb.collection(path.usersPath.doc(uid)); final DocumentSnapshot currentDocument=等待参考get(); 返回(currentDocument.exists)&& currentDocument.data.containsKey('username')&&//此处有错误 currentDocument.data.containsKey('age');//此处出错,flutter,dart,maps,Flutter,Dart,Maps,我不熟悉颤振和OOP。这是我正在学习的一些项目教程。但是项目中使用的颤振版本已被弃用。因此,我在升级它时遇到了此问题。以前的版本似乎对此没有问题。有人可以帮助我吗 dataproperty on是一种返回文档快照内容的方法。您需要先执行它,然后才能访问映射的属性 var data = { 'photoUrl': profileImageUrl, 'age': age, 'username': username, }; //ref.set
data
property on是一种返回文档快照内容的方法。您需要先执行它,然后才能访问映射的属性
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
谢谢您的回答。但是现在它说,“没有为类型“Object”定义方法“containsKey”。“您可能希望尝试将其强制转换为map
为map
或添加键入信息-DocumentSnapshot/DocumentReference具有通用属性t-DocumentReference
currentDocument.data().containsKey('username')