Flutter: Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform

Ace

I am new to flutter and i am building a social media App through tutorial which i am now customizing. Now I tried to add more input fields to a users profile page then i started getting the error below. When i could login my timeline page turned red with warning Bad state: field does not exist within the DocumentSnapshotPlatform

I ran Flutter clean and now my user cannot log into the app

I am getting this error:

E/flutter ( 3971): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform
E/flutter ( 3971): #0      DocumentSnapshotPlatform.get._findKeyValueInMap
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:82
E/flutter ( 3971): #1      DocumentSnapshotPlatform.get._findComponent
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:98
E/flutter ( 3971): #2      DocumentSnapshotPlatform.get
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:113
E/flutter ( 3971): #3      DocumentSnapshot.get
package:cloud_firestore/src/document_snapshot.dart:49
E/flutter ( 3971): #4      DocumentSnapshot.[]
package:cloud_firestore/src/document_snapshot.dart:56
E/flutter ( 3971): #5      new User.fromDocument
package:findemed/models/user.dart:46
E/flutter ( 3971): #6      _HomeState.createUserInFirestore
package:findemed/pages/home.dart:152
E/flutter ( 3971): <asynchronous suspension>
E/flutter ( 3971): #7      _HomeState.handleSignIn
package:findemed/pages/home.dart:60
E/flutter ( 3971): #8      _HomeState.initState.<anonymous closure>
package:findemed/pages/home.dart:46
E/flutter ( 3971): #9      _rootRunUnary (dart:async/zone.dart:1198:47)

The initial was pointing to this dart section of my home file

buildUsersToFollow() {
  return StreamBuilder(
    stream: usersRef.orderBy('timestamp', descending: true)
    .limit(0)
    .snapshots(),
    builder: (context, snapshot) {
      if (!snapshot.hasData) {
        return circularProgress(context);
      }
      List<UserResult> userResults = [];
      snapshot.data.docs.forEach((doc) {
        User user = User.fromDocument(doc);
        final bool isAuthUser = currentUser.id == user.id;
        final bool isFollowingUser = followingList.contains(user.id);
        // remove auth user from recommended list
        if (isAuthUser) {
          return;
        } else if (isFollowingUser) {
          return;
        } else {
          UserResult userResult = UserResult(user);
          userResults.add(userResult);
        }
        });


Now its pointing to this snippet:

factory User.fromDocument(DocumentSnapshot doc) {
    return User(
      id: doc['id'],
      email: doc['email'],
      username: doc['username'],
      photoUrl: doc['photoUrl'],
      displayName: doc['displayName'],
      bio: doc['bio'],      
      fullNames: doc['fullNames'],
      practice: doc['practice'],
      speciality: doc['speciality'],
      phone: doc['phone'],
      mobile: doc['mobile'],
      emergency: doc['emergency'],
      address: doc['address'],
      city: doc['city'],
      location: doc['location'],
    );
  }

and this is the other bit of code pointed out in the stack

currentUser = User.fromDocument(doc);
    print(currentUser);
    print(currentUser.username);
Rishi Malgwa
Change your factory to this:-
factory User.fromDocument(DocumentSnapshot doc) {
    return User(
      id: doc.data()['id'],
      email: doc.data()['email'],
      username: doc.data()['username'],
      photoUrl: doc.data()['photoUrl'],
      displayName: doc.data()['displayName'],
      bio: doc.data()['bio'],      
      fullNames: doc.data()['fullNames'],
      practice: doc.data()['practice'],
      speciality: doc.data()['speciality'],
      phone: doc.data()['phone'],
      mobile: doc.data()['mobile'],
      emergency: doc.data()['emergency'],
      address: doc.data()['address'],
      city: doc.data()['city'],
      location: doc.data()['location'],
    );
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

StateError (Bad state: field does not exist within the DocumentSnapshotPlatform) on flutter

flutter Bad state: field does not exist within the DocumentSnapshotPlatform

Flutter: Bad state: field does not exist within the DocumentSnapshotPlatform in streambuilder

Flutter - "Bad state: field does not exist within the DocumentSnapShotPlatform"

Bad state: field does not exist within the DocumentSnapshotPlatform flutter error even though field exists

Problem with stream and firebase Bad state: field does not exist within the DocumentSnapshotPlatform

Error: Bad state : field does not exist within the DocumentSnapshotPlatform

Bad state: field does not exist within the DocumentSnapshotPlatform error

How to fix Bad state: field does not exist within the DocumentSnapshotPlatform Firebase Flutter FutureBuilder

I tried to display 'DateTime' on flutter UI get from firestore but show " Bad state: field does not exist within the DocumentSnapshotPlatform "

StateError (Bad state: field does not exist within the DocumentSnapshotPlatform). How can I get a doc from firestore?

Bad state: field does not exist within the DocumentSnapshotPlatform. Giving this error but don't know where the error is

Exception: Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist provider

Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist, Firebase Flutter

Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist

How can I resolve " Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist"

field dos not exist within the DocumentSnapshotPlatform

Unhandled Exception: Bad state: Future already completed in flutter

Flutter | Unhandled Exception: Bad state: No element using 'firstWhere' and 'orElse'

Flutter Isolate: Unhandled Exception: Bad state: Stream has already been listened to

flutter: Unhandled Exception: Bad state: Cannot add new events after calling close

Flutter: Unhandled Exception: Bad state: Cannot add new events after calling close (NOT SAME CASE)

Futter/dart: [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Bad state: No element

flutter: Exception Happened: Bad state: No element in XML

An unhandled exception occurred: Job name "..getProjectMetadata" does not exist

Unhandled exception in FutureBuilder Flutter

Unhandled exception - Flutter

Flutter doctor unhandled exception

Unhandled Exception: Bad state: Cannot add new events after calling close Audio player