aarushi
aarushi

Reputation: 367

trouble retrieving data from firebase in flutter dart application. cannot get a field on a DocumentSnapshotPlatform which does not exist

Error im receiving : StateError (Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist)

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

the name field does exist in my firebase collection thing

here is an image of my database, ignore how gender says 10th lol

database

Upvotes: 2

Views: 4202

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

You need to do the following:

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

Upvotes: 4

Related Questions