Leewan
Leewan

Reputation: 63

Flutter: How to remove a specific array value in firebase?

In flutter, I want to Delete matching array value from the firebase Database. Here How the database look like
From there I want to delete array code value that matches input data. When user Pressed button I want to delete the array value in firebase Database.

TextFormField(
 style:
 labelText: 'CONFIRM',
 onChanged: (val) {
 setState(() {
    confirmCode = val; //user input val
  });
 },
),

RaisedButton(
onPressed: () async {                                          
 //here i want make a request to firebase to Delete
},
 child: Text('CONFIRM'),
),

Upvotes: 1

Views: 1314

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

To remove the value from the array, then try the following:

onPressed: () async {
var clientCollection = Firestore.instance.collection("client");
clientCollection.document("confirmCode").updateData({
  "code" : FieldValue.arrayRemove([int.parse(confirmCode)])
}).then((_) {
  print("success!");
});                                          
},

Using FieldValue.arrayRemove you can delete an item from the array.

Upvotes: 2

Related Questions