title: How do I retrive firebase data in flutter
body: <p>I am trying to get a list of data from a firebase database and display it as a list in my flutter app, at the moment I cannot get the data to appear, on the UI.When I try and print the list it does not contain any values when it should show the names I have entered in the database.  </p>
  
  <p>This is the database that I am trying to retrieve:</p>
  
  <p><img src="https://i.stack.imgur.com/GWf8c.png" alt="This is the database that I am trying to retrieve:"></p>
  
  <p>This is the code that I have implemented for my UI, any ideas on what is the issue here? </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'package:firebase_database/firebase_database.dart';
  import 'package:firebase_database/ui/firebase_animated_list.dart';
  import 'SignInSuccessPage.dart';
  
  class SignInPage extends StatefulWidget {
    @override
    SignInPageState createState() =&gt; SignInPageState();
  }
  
  class SignInPageState extends State&lt;SignInPage&gt; {
    List&lt;Volunteer&gt; volunteers;
    Volunteer volunteer;
    DatabaseReference volunteerRef;
  
  
    @override
    void initState() {
      super.initState();
      volunteers = new List();
      volunteer = Volunteer("","", "");
      final FirebaseDatabase database = FirebaseDatabase.instance; /
      volunteerRef = database.reference().child('volunteerapp-cec4f');
      volunteerRef.onChildAdded.listen(_onEntryAdded);
      volunteerRef.onChildChanged.listen(_onEntryChanged);
  
    }
  
    _onEntryAdded(Event event) {
      setState(() {
        volunteers.add(Volunteer.fromSnapshot(event.snapshot));
      });
    }
  
    _onEntryChanged(Event event) {
      var old = volunteers.singleWhere((entry) {
        return entry.key == event.snapshot.key;
      });
      setState(() {
        volunteers[volunteers.indexOf(old)] = Volunteer.fromSnapshot(event.snapshot);
      });
    }
  
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('List of Names'),
        ),
        resizeToAvoidBottomPadding: false,
        body: Column(
          children: &lt;Widget&gt;[
            Flexible(
              child: FirebaseAnimatedList(
                query: volunteerRef,
                itemBuilder: (BuildContext context, DataSnapshot snapshot,
                    Animation&lt;double&gt; animation, int index) {
                  return new ListTile(
                    title: Text(volunteers[index].firstName),
                    subtitle: Text(volunteers[index].lastName),
  
                  );
                },
              ),
            ),
          ],
        ),
      );
    }
  }
  
  //the volunteer class which contains all the info about each volunteer object and links to firebase
  class Volunteer {
    String key;
    String firstName;
    String lastName;
  
    Volunteer(this.key, this.firstName, this.lastName);
  
    Volunteer.fromSnapshot(DataSnapshot snapshot)
        : key = snapshot.key,
          firstName = snapshot.value["firstName"],
          lastName = snapshot.value["lastName"];
  
    toJson() {
      return {
        "key": key,
        "firstName": firstName,
        "lastName": lastName,
      };
    }
  }</code></pre>
  </div>
  </div>
  </p>