1
votes

I have a function to query firestore and retrieve a specific user but I keep getting the same error.

The error I got was the following:

I/flutter (29600): The following NoSuchMethodError was thrown building SellerInfo(dirty, state:
I/flutter (29600): _SellerInfoState#90e11):
I/flutter (29600): Class 'Future<User>' has no instance getter 'displayName'.
I/flutter (29600): Receiver: Instance of 'Future<User>'
I/flutter (29600): Tried calling: displayName
I/flutter (29600):

I first tried this:

Future<User> getUser(String displayName) async{
    await Firestore.instance.collection('users')
                           .where('displayName', isEqualTo: displayName)
                           .snapshots()
                           .listen( (QuerySnapshot onData) {
                             List<User> user = onData.documents.map(
                               (DocumentSnapshot doc) => _fromUserSnapShot(doc)
                             );
                             return user.first;
                           });
    return null;


  }

and then

Future<User> getUser(String displayName) async{
    return (await Firestore.instance.collection('users')
                           .where('displayName', isEqualTo: displayName)
                           .getDocuments())
                           .documents
                           .map((DocumentSnapshot doc) => _fromUserSnapShot(doc))
                           .first;
  }

This is the user class

class User {
    final String displayName;
    final String email;
    final String school;

    User({
      @required this.displayName,
      @required this.email,
      @required this.school,
    });
}
1

1 Answers

0
votes

Try to get the document of that user directly : Firestore.instance.collection('users').document(displayName).get()