title: Flutter Function returns empty list using Firebase
body: <p>I'm using Flutter web and firebase realtime database. In my databse I have some questions, structured as maps, and I'm trying to display them in my app.</p>
  <p>For each question, I create a widget, I add it inside a list and then I append the list to a <code>Column()</code> widget.</p>
  <p>The <code>Column()</code> widget is the following (<code>view_question.dart</code> file):</p>
  <pre><code>Column(
    children: Question().view(),
  ),
  </code></pre>
  <p>As you can see, I use the method <code>view()</code> from a class I created named <code>Question()</code>.</p>
  <p>The <code>view()</code> method returns a list of widgets.</p>
  <p>Before I show you the <code>.view()</code> method, I need to mention that outside of the <code>Question</code> class I have initialized the following:</p>
  <pre><code>List&lt;Widget&gt; widgets = List();
  </code></pre>
  <p>Below you can see the <code>.view()</code> method from the <code>Question</code> class (<code>Question.dart</code> file):</p>
  <pre><code>List&lt;Widget&gt; view() {
      
      Database db = database();
      DatabaseReference ref = db.ref('questions/');
  
      ref.orderByKey().once(&quot;value&quot;).then((e) {
        DataSnapshot datasnapshot = e.snapshot;
        datasnapshot.val().forEach((key, values) {
          
          widgets.add(QuestionWidget(values));
          print(widgets);
          
        });
      });
      print(widgets);
      return widgets;
  </code></pre>
  <p>I'm getting my questions' data from my database, then for each question I'm creating a <code>QuestionWidget()</code> widget, where I pass inside it the respective data and I add it to the <code>widgets</code> list. Afterwards, I <code>print()</code> the <code>widgets</code> list, so I can monitor the whole process.</p>
  <p>As you also can see, I've added a <code>print(widgets)</code> just before the <code>return</code> statement.</p>
  <p>This is the prints' output in my console</p>
  <p><a href="https://i.stack.imgur.com/qZ6b7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qZ6b7.png" alt="enter image description here" /></a></p>
  <p>From that, what I understand is that the function returns an empty list and then I retrieve my data from the database and add them to the list.</p>
  <p>So I'm asking, how can I add my data to the list, and when this process has finished, return the list and append it to the <code>Column()</code> widget? Should I add a delay to the return statement? What am I missing?</p>
  <p>Thank you for your time</p>