我正在尝试从Firestore检索数据并将val放入if语句中,但是当我这样做时,它给了我这个错误:
I/flutter ( 8492): Closure: () => String from Function 'toString':.
这是我的代码:
void getUserData() async {
try {
firestoreInstance
.collection('Users')
.document(usernameController.text)
.get()
.then((value) {
setState(() {
email = (value.data)['email'];
password = (value.data)['password'];
gender = (value.data)['gender'];
username = (value.data)['username'];
userType = (value.data)['userType'];
});
});
} catch (e) {
print(e.toString);
}
}
忘了提到当我打印userType这是一个文本时,它会给我NULL。
答案 0 :(得分:1)
只需删除您的()
void getUserData() async {
try {
firestoreInstance
.collection('Users')
.document(usernameController.text)
.get()
.then((value) {
setState(() {
email = value.data['email'];
password = value.data['password'];
gender = value.data['gender'];
username = value.data['username'];
userType = value.data['userType'];
});
});
} catch (e) {
print(e.toString);
}
}
或这样使用
username = value['username'];