{
"centers": {
"DCSE": {
"centerName": "DC"
},
"SE": {
"centerName": "ccc"
},
}
}
stdRef =FirebaseDatabase.instance.ref().child('centers').child('centerName');
i would like to access centerName without knowing its nodes names DCSE and SE as its possible to do? i want to access centerName with parent name cneter
instead of centers.DCSE.centerName
child('centers').child('centerName') directly????
CodePudding user response:
If you don't know which center to show the name of, all you can do is show the name of all centers. That'd be something like:
final centersRef = FirebaseDatabase.instance.ref("centers");
centersRef.onValue.listen((event) {
for (final centerSnapshot in event.snapshot.children) {
print('${centerSnapshot.child("centerName").value}');
}
}, one rror: (error) {
// Error.
});
Also see the Firebase documentation on listening for value events.