I managed to get one data from Firebase Realtime Database. This time I want to turn it into JSON format and get two data at least. Below is the code
my Database Reference `
DatabaseReference ref =
FirebaseDatabase.instance.ref().child('UsersData/$userDataUID/test/int');
my code `
StreamBuilder(
stream: ref.onValue,
builder: (context, snapshot) {
if (snapshot.hasData) {
debugPrint(snapshot.data?.snapshot.value.toString());
}
return const CircularProgressIndicator();
})),
I believe I have to convert it into Maps? I have no idea how to begin with
CodePudding user response:
Try with
DatabaseReference ref =
FirebaseDatabase.instance.ref().child('UsersData/$userDataUID/test');
This will return a map with those fields.
And use on widget like
if (snapshot.hasData) {
final map = snapshot.data?.snapshot.value as Map?;
return Text("int: ${map?["int"]} voltage: ${map?["voltage"]}"); }
Find more about getting data