【发布时间】:2021-09-22 01:14:51
【问题描述】:
我正在运行我的 Flutter 应用程序并收到此错误:
The method '[]' was called on null.
Receiver: null
Tried calling: []("id")
这是我的用户类:-
class User {
final String id;
final String username;
final String email;
final String photoUrl;
User({
this.id,
this.username,
this.email,
this.photoUrl,
});
factory User.fromDocument(DocumentSnapshot doc) {
return User(
id: doc.data()['id'],
username: doc.data()['username'],
email: doc.data()['email'],
photoUrl: doc.data()['photoUrl'],
);
}
}
数据库中的文档不为空, 什么可能导致这个问题??
【问题讨论】:
-
您在代码执行期间是否尝试打印
doc.data()?
标签: firebase flutter google-cloud-firestore