I am new t flutter and following documentations as most of the courses and videos are outdated but DatabaseEvent event.snapshot.value is not printing any value This is my data is RealTime Database of firebase and I want to read it.

users
  3I4SCTCeyJVKWYvdnU2NHLmoTYV2
      email: "[email protected]"
      name: "riomobility"
      phone: "+923031521515"

this is my code: Reference is getting printed but DatabaseEvent event.snapshot.value is not. Please help thank you

 DatabaseReference reference =
        FirebaseDatabase.instance.ref("user").child(userId).child("name");

    DatabaseEvent event = await reference.once();

    print(reference.key);
    print(reference.parent!.key);

    print(event.snapshot.value);

printed results:

I/flutter (19657): name
I/flutter (19657): 3I4SCTCeyJVKWYvdnU2NHLmoTYV2
I/flutter (19657): null

what am I doing wrong?


Solution 1: mobdev991

So, after trying everything, nothing worked but finally something did as I was shuffling my code. So,

DatabaseReference reference =
        await FirebaseDatabase.instance.ref().child("users").child(userId);

    DatabaseEvent event = await reference.once();

    DataSnapshot snap = event.snapshot;

print(snap.value);

not this printing value..

I thought even.snapshot.value is the same as above code but it wasn't.