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


I’m getting an error in a FutureBuilder while trying to retrieve data from the Firestore database.  The error message is:

The following StateError was thrown building
FutureBuilder<DocumentSnapshot<Object?>>(dirty, state:
_FutureBuilderState<DocumentSnapshot<Object?>>#9feea): Bad state: field does not exist within the DocumentSnapshotPlatform

The relevant error-causing widget was:  

I reviewed different SO threads and and still have no idea what to do to fix my code.  Firebase is definitely working properly and I don’t see any missing fields.  Any help will be appreciated.  Thanks.

class ProfileTab extends StatefulWidget {
  const ProfileTab({
    Key? key,
  }) : super(key: key);

  State<ProfileTab> createState() => _ProfileTabState();

class _ProfileTabState extends State<ProfileTab> {
  final currentUser = Auth().currentUser?.uid;

  Widget build(BuildContext context) {
    return SafeArea(
        child: CustomScrollView(slivers: <Widget>[
          child: FutureBuilder<DocumentSnapshot<Map<String, dynamic>>>(
              future: Auth().usersReference.doc(currentUser).get(),
              builder: (context, snapshot) {
                if (snapshot.connectionState == ConnectionState.waiting) {
                  return const AdaptiveCircularProgress();
                AppUser appUser = AppUser.fromDocument(;
                return UserProfileHeaderContainer(headerContent: []);

class AppUser {

  final String? bio;
  final String? displayName;
  final List? followers;
  final List? following;
  final String? photoUrl;
  final List? userCart;
  final String? userID;
  final String? userName;

  factory AppUser.fromDocument(DocumentSnapshot? doc) {
    return AppUser(
      bio: doc?[],
      displayName: doc?[FirebaseString.displayName],
      followers: doc?[FirebaseString.followers],
      following: doc?[FirebaseString.following],
      photoUrl: doc?[FirebaseString.photoUrl],
      userCart: doc?[FirebaseString.userCart],
      userID: doc?[FirebaseString.userID],
      userName: doc?[FirebaseString.userName],

  Map<String, dynamic> toJson() => { bio,
    FirebaseString.displayName: displayName,
    FirebaseString.followers: followers,
    FirebaseString.following: following,
    FirebaseString.photoUrl: photoUrl,
    FirebaseString.uid: userID,
    FirebaseString.userCart: userCart,
    FirebaseString.userName: userName,


You are parsing it wrong. You need to do something like.

factory AppUser.fromDocument(DocumentSnapshot<Map<String, dynamic>> doc) {

// it's the data map which has all the info
final map =

return AppUser(
  bio: map[],

Answered By – aman

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *