I hooked up firebase and made the save data in it. But I can\'t delete a specific entry in firebase.
I tried deleting through method that I wrote below. But it doesn\'t
In order to delete a node, you need to know the complete path to that node. If you don't know that complete path, you can use a query to determine it.
So in your case, if you know the phone number of the node you want to delete, you can query for all nodes with that phone number (since there may be multiple) and then delete them.
The code for this would look something like:
FirebaseDatabase.instance.reference()
.child('customers')
.orderByChild('phoneNumber')
.equalTo('+79644054946')
.onChildAdded.listen((Event event) {
FirebaseDatabase.instance.reference()
.child('customers')
.child(event.snapshot.key)
.remove();
}, onError: (Object o) {
final DatabaseError error = o;
print('Error: ${error.code} ${error.message}');
});
Update (20200221): You can also use a once()
listener and loop over its child nodes with:
FirebaseDatabase.instance.reference()
.child('customers')
.orderByChild('phoneNumber')
.equalTo('+79644054946')
.once()
.then((DataSnapshot snapshot) {
Map children = snapshot.value;
children.forEach((key, value) {
FirebaseDatabase.instance.reference()
.child('customers')
.child(key)
.remove();
})
});