Aslan Mahy
Aslan Mahy

Reputation: 3

How can i fetch a field from a specific only

I have this simple data in Firebase Realtime Database:

secreenshot

Now i need to fetch data by using this code :

Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.deepPurple,
      appBar: AppBar(),
      body:  SingleChildScrollView(
        child: FirebaseAnimatedList(
          shrinkWrap: true,

          query: FirebaseDatabase.instance.reference(),
          itemBuilder: (BuildContext context, DataSnapshot snapshot,Animation<double> animation,  int index) {
            return Text(snapshot.value["name"]);
          },),
      ),
    );
  }

With this code i will get two fields fetched in UI which are [name : Andy] and [name:Derek]

for more explain i screenshot this data

secreenshoot

but How could i fetch only one field? Let's say i need to fetch only [name : Andy] which is under User 1 child.

Upvotes: 0

Views: 35

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

Try the following:

FirebaseDatabase.instance.reference().child("User 1");

This will return the User 1 object

Upvotes: 1

Related Questions