Home > OS >  How to print to console or get the key of a firestore document field in flutter
How to print to console or get the key of a firestore document field in flutter

Time:05-30

I want to print the underlined value (med 1) to the console. How can I do that? I am using a streamBuilder to display the data and I want to display the key as a text widget.

enter image description here

CodePudding user response:

StreamBuilder(
  stream: Firestore.instance.collection('/your_collection_name').snapshots()
  builder: (_, AsyncSnapshot<QuerySnapshot> snapshot) {
    if(snapshot.hasData){
      snapshot.data!.docs.map((DocumentSnapshot document) {
                Map<String, dynamic> data =
                    document.data()! as Map<String, dynamic>;
                print(data['med 1'];
              })
}
)

If you have multiple documents under the collection with med 1 field, you can access the data using this code.

Hope it helps

  • Related