在Flutter Dart应用程序中从Firebase检索数据时遇到问题。无法在不存在的DocumentSnapshotPlatform上获取字段

时间:2020-10-02 20:48:03

标签: firebase flutter dart google-cloud-firestore

我收到错误消息: StateError(错误状态:无法在不存在的DocumentSnapshotPlatform上获取字段)

Future getUserInterests(userId) async {
    User currentUser = User();

    await _firestore.collection('users').doc(userId).get().then((user) {
      currentUser.photo = user.get('name');
      currentUser.photo = user.get('photoUrl');
      currentUser.gender = user.get('gender');
      currentUser.subject = user.get('subject');
      
    });
    return currentUser;
  }

名称字段确实存在于我的Firebase收藏夹中

这是我数据库的图像,请忽略性别如何表示第十个笑声

database

1 个答案:

答案 0 :(得分:3)

您需要执行以下操作:

currentUser.name = user.data()['name'];
currentUser.photo = user.data()['photoUrl'];
currentUser.gender = user.data()['gender'];
currentUser.subject = user.data()['subject'];