Bad state: field does not exist within the DocumentSnapshotPlatform

Bad state: field does not exist within the DocumentSnapshotPlatform

Solution :

  • Resolve Field Not Exist issue with Try-Catch

Code Example :

import 'package:cloud_firestore/cloud_firestore.dart';

class ModelClassName {
  final String id;
  final String Name;
  bool isAdmin;


  ModelClassName({
    this.id,
    this.Name,
    this.isAdmin
  });

  factory ModelClassName.fromDocument(DocumentSnapshot doc) {

    bool isAdmin = false;
    try {
      isAdmin = doc.get("isAdmin");
    } on Exception catch (exception) {
      isAdmin=false;
    } catch (error) {
      isAdmin=false;
    }


    return ModelClassName(
        id: doc.reference.id,
        Name: doc.get("Name"),
        isAdmin: isAdmin,
    );


  }
}

Leave a Reply

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



×

    Request a Proposal

    Fill Out Our Form & We’ll be in Touch Shortly

    Type of Project



    Our Locations

    PH: +1-202-938-5932

    USA

    10630 Little Patuxent Pkwy,
    Suite 314-M7
    Columbia, MD 21044

    UK

    120 Bark Street
    6th & 7th Floor
    Bolton Lancashire, United Kingdom Bl12ax

    Australia

    443 Camp Rd, Broadmeadows
    VIC, Australia