gpt4 book ai didi

firebase - 如何在flutter中从Firebase数据库检索数据?

转载 作者:行者123 更新时间:2023-12-03 04:44:22 28 4
gpt4 key购买 nike

我正在尝试从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。

最佳答案

just remove your ()

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);
}
}

or use like this

username = value['username'];

关于firebase - 如何在flutter中从Firebase数据库检索数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62549316/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com