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

myke

I'm new to flutter. I want to get a specific doc from firestore using its uid and then transfer this doc in a value type that I can handle. BUT i get a breakpoint when I run my application : StateError (Bad state: field does not exist within the DocumentSnapshotPlatform). This the code:

final cloth = await DatabaseService(uid: uid)
          .clothCollection
          .doc(uid)
          .get()
          .then((doc) => {
                            Cloth(
                    brand: doc.get('brand'),
                    name: doc.get('name'),
                    color: doc.get('color'),
                    url: doc.get('url'))
              });

and Cloth :

class Cloth {
  final String? name;
  final String? url;
  final String? brand;
  final String? color;

  Cloth({this.name, this.brand, this.color, this.url});
}

If there is an easier way to get this doc let me know. Thanks for your help!

Unbreachable

The get attribute does not exist on the DocumentSnapshot(doc). Instead, you have to use the data() method which returns a Map<String, dynamic>, or null if the doc does not exist. It's good practice to always check to see if the document exists first before executing further.

final cloth = await DatabaseService(uid: uid)
          .clothCollection
          .doc(uid)
          .get()
          .then((doc) {
            if (doc.exists) {
            Map<String, dynamic>? data = doc.data();

              return Cloth(
                    brand: data?['brand'],
                    name: data?['name'],
                    color: data?['color'],
                    url: data?['url']);
           } else {
              print('Document does not exist.');
            }
              });

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

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

How to get the modified field or data from the doc Firebase Firestore realtime updates?

How can I get specific document data from firestore querysnapshot?

How can I get a list from state and modify it in qore?

How to Get Array Field Values From Firestore

Can I update a parent state from within a Dialog in Flutter?

how to check if Field exist in document in firestore database?

Flutter Firestore - How to get data from a Document Reference in a Document Field?

How to get field from multiple-layer document in Firestore

How to get doc from firebase?

How can I get Timestamp from Firestore server without bothering for the case when device clock is out of sync with Firestore

'Session' does not exist in the current context. How can I use it?

Geting doc from the firestore

Problema com stream e firebase Bad state: o campo não existe em DocumentSnapshotPlatform

Property 'payload' does not exist on type 'TypedAction. How i can access the action.payload from a ngrx effect?

How can I get a Value from my Database and use and show it inside an Input Field?

How can I get the fields from another mongodb collection and add those field values as an array in the current collection?

Why I can't set state to Firebase's doc data?

how can i get single firestore document dynamically in flutter

How can i get in jQuery the current state of an infinite animation in CSS

How can I get the creator of a State for Hyperledger Fabric in chaincode?

How can I make a stream of parent/child objects from firestore

Firestore! How can I remove a map from array by javascript code?

How do I get data in subcollection from filtered document in Firestore

How do I get the data from a document in a collection in Firestore?

How can I remove commas or whatever from within a string?

How can I launch Nuke from within Maya?

How can I render a partial view from within a layout file?

How can I select the last element from a list within a for loop?

TOP lista

quentelabel

Arquivo