title: Flutter - How to retrieve a list of IDs from Firestore and display their items in GridView?
body: <p>I'm developing a book app and I need to display a favorite list from each user, I can save all favorites in array in firestore but I don't know how to retrieve them to my grid.I used StreamBuilder to retrieve all books but now I don't know if I need to store them to show and how. I tried to retrieve all favorites ids to a list of strings then load them in my GridView but the list is null.</p>
  
  <p>Here is how my Firestore:</p>
  
  <p><a href="https://i.stack.imgur.com/mxeia.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mxeia.jpg" alt="Books Firestore"></a>
  <a href="https://i.stack.imgur.com/kNG2V.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kNG2V.jpg" alt="Users Firestore"></a></p>
  
  <pre><code>class _FavoriteScreenState extends State&lt;FavoriteScreen&gt; {
  
    UserModel model = UserModel();
    FirebaseUser firebaseUser;
    FirebaseAuth _auth = FirebaseAuth.instance;
    List&lt;String&gt; favorites;
  
  
    Future&lt;List&lt;String&gt;&gt; getFavorites() async{
  
    firebaseUser = await _auth.currentUser();
  
    DocumentSnapshot querySnapshot = await Firestore.instance.collection("users")
        .document(firebaseUser.uid).get();
    if(querySnapshot.exists &amp;&amp; querySnapshot.data.containsKey("favorites") &amp;&amp;
      querySnapshot.data["favorites"] is List){
      return List&lt;String&gt;.from(querySnapshot.data["favorites"]);
  
    }
    return [];
  
    }
  
  
    @override
    Widget build(BuildContext context) {
  
  
      Widget _buildGridItem(context, index){
  
        return Column(
          children: &lt;Widget&gt;[
            Material(
              elevation: 7.0,
              shadowColor: Colors.blueAccent.shade700,
              child: InkWell(
                onTap: (){
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) =&gt; DetailScreen(document)
                  ));
                },
                child: Hero(
                  tag: index['title'],
                  child: Image.network(
                    index["cover"],
                    fit: BoxFit.fill,
                    height: 132,
                    width: 100,
                  ),
                ),
              ),
            ),
            Container(
              width: 100,
              margin: EdgeInsets.only(top: 10, bottom: 5),
              child: Text(index["title"],
                textAlign: TextAlign.center,
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
                style: TextStyle(
                  fontSize: 10,
                  fontWeight: FontWeight.w900,
  
                ),
              ),
            ),
          ],
        );
      }
  
      return Scaffold(
  
        body: favorites != null ? Stack(
          children: &lt;Widget&gt;[
            GridView.builder(
              padding: EdgeInsets.fromLTRB(16, 16, 16, 16),
              primary: false,
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3,
                childAspectRatio: MediaQuery.of(context).size.width /
                    (MediaQuery.of(context).size.height),
                //crossAxisSpacing: 3,
                //mainAxisSpacing: 3
              ),
              itemBuilder: (context, index){
                return _buildGridItem(context, favorites[index]);
              },
  
  
            )
  
          ],
        )
        :
         Center(child: CircularProgressIndicator())
      );
    }
  
    @override
    void initState() async {
      // TODO: implement initState
      super.initState();
      favorites = await getFavorites();
    }
  
  }
  </code></pre>