I have a firebase realtime tree which has a particular node New Ride
set when the user is online, when offline the node New Ride
gets removed. This works ok for the first time, When the user tries to go online again I can't set up the node. I want to check if the node already exists in the tree if not add it.
This is my code so far
DatabaseReference rideRequestRef = FirebaseDatabase(databaseURL: firebaseUrl)
.reference()
.child("Drivers")
.child(currentFirebaseUser.uid)
.child("New Ride");
var ref = FirebaseDatabase(databaseURL: firebaseUrl)
.reference()
.child("Drivers")
.child(currentFirebaseUser.uid);
await ref
//.child(currentFirebaseUser.uid)
.child("New Ride")
.once()
.then((DataSnapshot dataSnapshot) {
if (dataSnapshot == null) {
rideRequestRef.set("searching");
} else {
rideRequestRef.set("searching");
}
});
rideRequestRef.onValue.listen((event) {});
}