Reputation: 63
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
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