Update the Map field - Flutter

Viewed 3026

How to update data of isVerified (Boolean) field. Personal Info is Map contains address and then isVerified.

enter image description here

3 Answers

To update isVerified, you have to do the following:

Firestore.instance.collection("collection Name").document("documentId").updateData({
    "Personal Info.address.isVerified": true,
  }).then((_) {
    print("success!");
  });

Since you did not provide your collection or document name I would just form one

So lets assume every time we click a button the value should be changed to true

CollectionReference humanCollection = Firestore.instance.collection("collection Name");
//This is the button
FlatButton(
onPressed: () => changeValue();
 child : Container(
   Text : 'Change Value'
)
),

//This is the function

changeValue(){

humanCollection
        .document(currentHuman.id)//put the document name here
        .updateData({
          'Personal Info.address.isVerified' : true,
         });
}

It is very easy use below line where ever you want to update data in firebase.

. is used to access key of sub-map.

  await FirebaseFirestore.instance.collection('collection Name').doc('documentId').update({'Personal Info.address.isVerified' : true,});

version : cloud_firestore: 3.1.11

Related