title: How to get data from database and into listview.builder
body: <p>I am trying to get data from Firebase RTDB and then display them as a list using Listview.builder.</p>
  <p>This worked well before, however I have added a new node into my database to have it be more stuctured. The problem is, inspite of there being data, it's showing up as empty when I try to retrieve it.</p>
  <p><strong>Database before:</strong> <a href="https://i.stack.imgur.com/llDS6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/llDS6.png" alt="enter image description here" /></a></p>
  <p><strong>Database Now:</strong> <a href="https://i.stack.imgur.com/qHmNz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qHmNz.png" alt="enter image description here" /></a></p>
  <p><strong>Code:</strong></p>
  <pre><code>Future&lt;List&gt; getParentDetails() async {
      schoolName = await getSchoolName();
      databaseReference
          .child(&quot;users&quot;)
          .child(schoolName.toString()) // (newly added)
          .child(&quot;parents&quot;)
          .onValue
          .listen(
        (event) {
          if (event.snapshot.exists) {
            setState(
              () {
                var value = event.snapshot.value;
                parentList = Map.from(value)
                    .values
                    .map((e) =&gt; Parents.fromJson(Map.from(e)))
                    .toList();
              },
            );
          } else {
            print(&quot;No Data Exists&quot;);
          }
        },
      );
      return parentList;
    }
  </code></pre>
  <p><strong>UI Code:</strong></p>
  <pre><code>ListView.builder(
    itemCount: parentList.length,
    itemBuilder: (context, int index) {
      final Parents parents = parentList[index];
      final String parentEmail = parents.email;
      final String parentName = parents.name;
      final String parentPhone = parents.phone;
      
      // final String parentUID = parents.uid;
      return Padding(
        padding: const EdgeInsets.all(8.0),
        child: Card(
          elevation: 0.2,
          child: ExpansionTile(
            // collapsedBackgroundColor: Colors.grey,
            title: Text(
              parentName.toUpperCase(),
              style: GoogleFonts.lexendMega(
                fontSize: 12,
              ),
              textAlign: TextAlign.center,
            ),
            children: [
              Column(
                children: [
                  Text(
                    parentEmail,
                    textAlign: TextAlign.center,
                    style: GoogleFonts.lexendMega(fontSize: 12),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Text(
                    parentPhone,
                    textAlign: TextAlign.center,
                    style: GoogleFonts.lexendMega(fontSize: 12),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                ],
              )
            ],
          ),
        ),
      );
    },
  ),
  </code></pre>
  <p><strong>New Edit:</strong></p>
  <pre><code>getSchoolName() async {
      // ignore: unused_local_variable
      final ref = FirebaseDatabase.instance.reference();
      User user = auth.currentUser;
      String adminUID = user.uid.toString();
      print(&quot;Getting School Name&quot;);
      databaseReference.child(&quot;users&quot;).child(&quot;admin&quot;).child(adminUID).once().then(
        (DataSnapshot snapshot) {
          setState(() {
            schlName = snapshot.value[&quot;school&quot;];
            print(schlName); //  (Prints - Highway Secondary School)
          });
        },
      );
      return await schlName;
    }
  
    Future&lt;List&gt; getParentDetails() async {
      schoolName = await getSchoolName();
      databaseReference
          .child(&quot;users&quot;)
          .child(&quot;Highway Secondary School&quot;)
          .child(&quot;parents&quot;)
          .onValue
          .listen(
        (event) {
          if (event.snapshot.exists) {
            setState(
              () {
                var value = event.snapshot.value;
                print(value); //  (See print value below)
                parentList = Map.from(value)
                    .values
                    .map((e) =&gt; Parents.fromJson(Map.from(e)))
                    .toList();
              },
            );
          } else {
            print(&quot;No Data Exists&quot;);
          }
        },
      );
      return parentList;
    }
  </code></pre>
  <p>Output:</p>
  <blockquote>
  <p>{L9LnmRTZJgVJWjNhrcTqoRdMlas2: {driver: Locate the driver: , phone: ********, school: Highway Secondary School, name: Parent One, user uid: L9LnmRTZJgVJWjNhrcTqoRdMlas2, email: **********@gmail.com}, Z9nHn3HZ3MZqgS7RsKsFiofD4ty2: {driver: Locate the driver: , phone: ********, school: Highway Secondary School, name: Parent Two, user uid: Z9nHn3HZ3MZqgS7RsKsFiofD4ty2, email: ***********@gmail.com}}</p>
  </blockquote>
  <p>Edit 2:</p>
  <pre><code> Future&lt;List&gt; getParentDetails() async {
      schoolName = await getSchoolName();
      print(schoolName);  (Prints - null)
  
      var ref = databaseReference.child(&quot;users/$schoolName/parents&quot;);
      var snapshot = await ref.get();
      if (snapshot.exists) {
        setState(() {
          var value = snapshot.value;
          parentList = Map.from(value)
              .values
              .map((e) =&gt; Parents.fromJson(Map.from(e)))
              .toList();
        });
      } else {
        print(&quot;No Data Exists&quot;);
      }
      return parentList;
  }
  </code></pre>
  <p>With newly added line of code above, the code doesn't get any data from the database (from the current database).</p>
  <p>Without the newly added line of code, I get data from the old database without any issues.</p>
  <p>The intention of the new database is to be more organized.</p>