Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

firebase - DocumentSnapshot in a FutureBuilder : Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist

I've been struggling with an error that is apparently due to new changes of DocumentSnapshot that I'm trying to use in a FutureBuilder you can see how i'm using it below :

body: FutureBuilder(
  future: usersRef.doc(widget.userId).get(),
  builder: ( context,  snapshot) {
    List<Widget> children;
    if (!snapshot.hasData) {
      return Center(
        child: CircularProgressIndicator(),
      );
    }
    else if (snapshot.hasData) {
      UserModel user = UserModel.fromDoc(snapshot.data);
factory UserModel.fromDoc(DocumentSnapshot doc) {
  return UserModel(
    id: doc.id,
    name: doc['name'],
    username: doc['username'],
    password: doc['password'],
    profileImageUrl: doc['profileImageUrl'],
    email: doc['email'] ,
    userIds: doc['userIds'] ?? '',
  );
}

I encounter this error:

The following StateError was thrown building FutureBuilder<DocumentSnapshot>(dirty, state: _FutureBuilderState<DocumentSnapshot>#46a8d):
Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist

I already tried to solve it using the solution that I found on this github issue ( https://github.com/FirebaseExtended/flutterfire/issues/3826) but It didn't really solve it.
I'll be so appreciative if any of you help me with this Thanks

question from:https://stackoverflow.com/questions/65862565/documentsnapshot-in-a-futurebuilder-bad-state-cannot-get-a-field-on-a-documen

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...