title: How to get list of document ids?
body: <p>I am trying to retrieve a list of document Ids from firestore.
  My firestore functions are stored as static methods in a FirebaseAPI class I created.</p>
  <p>This is the function that should return the list of documentIds:</p>
  <pre><code>static List&lt;String&gt; avaiableDocuments() {
  
    List&lt;String&gt; ids = [];
  
    final Future&lt;QuerySnapshot&gt; snapshot = Firestore.instance.collection('admin').getDocuments();
  
    snapshot.then((value) {
      value.documents.forEach((element) {
        ids.add(element.documentID);
      });
    });
  
    return ids;
  }
  </code></pre>
  <p>When I restart the app, the list of document ids do not appear.
  However, they do appear when the is then hot reloaded.</p>
  <p>My understanding is that when the app restarts, the list of strings is still empty.
  This is because the page renders before the future returns.
  Then when hot reload calls the build method again, the list is already populated so it displays it.</p>
  <p>I tried adding &quot;await&quot; before the getDocuments call.
  This turns the Future to just QuerySnapshot. Fair Enough.
  Now &quot;async&quot; must be added to the function.
  Then the function is now requiring a future return instead of a list.</p>
  <p>Can't I just get a list from this function?</p>
  <p>I tried to go with it and ended up with this:</p>
  <pre><code>static Future&lt;List&lt;String&gt;&gt; avaiableDocuments() async{
    List&lt;String&gt; ids = [];
  
    final QuerySnapshot snapshot = await Firestore.instance.collection('admin').getDocuments();
    snapshot.documents.forEach((element) {
      ids.add(element.documentID);
    });
  
    return ids;
  }
  </code></pre>
  <ol>
  <li>How is it that I'm allowed to return a list from a function that says it's returning a future?</li>
  <li>When I tried to consume the future in the screen class, same thing happens. List only appears on hot reload after restart.</li>
  </ol>
  <p>Note: I feel it's a simple issue, but I pretty much a noob when it comes to asynchronous voodoo.</p>
  <hr />
  <p>Class that should display the list of document Ids</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:hisab/database/firestore_api.dart';
  
  
  class PreviousCarts extends StatefulWidget {
    const PreviousCarts({Key key}) : super(key: key);
  
    @override
    _PreviousCartsState createState() =&gt; _PreviousCartsState();
  }
  
  class _PreviousCartsState extends State&lt;PreviousCarts&gt; {
  
    List&lt;String&gt; documentIds = [];
  
    @override
    void initState() { 
      super.initState();
      Future&lt;List&lt;String&gt;&gt; f = FirestoreAPI.avaiableDocuments();
      f.then((value) {
        value.forEach((element) {
          documentIds.add(element);
        });
      });
    }
  
    @override
    Widget build(BuildContext context) {
      print(documentIds);
      return Material(
        child: Padding(
          padding: const EdgeInsets.only(left: 8.0, top: 8.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: documentIds.map((e) {
              return Card(child: ListTile(title: Text(e)));
            }).toList(),
          ),
        ),
      );
    }
  }
  </code></pre>