title: Flutter - Getting data from firestore in a loop
body: <p>So basically I have a collection a User and within each user there is a subcollection for the pending friend request that the user have, something like that:</p>
  
  <p>/users/[auto-id]/friend_requests/[auto-id]/{user: ref to another user}</p>
  
  <p>But one user can obviously have multiple requests at the same time and I have an hard time to get the data correctly.</p>
  
  <p>What I'm correctly trying to do is to get a list of user that are in the subcollection "friend_requests":</p>
  
  <pre><code>_loadFriendRequests() async {
      try {
        this._users.addAll(await _dataService.fetchFriend());
      } catch (e, stackTrace) {
        printException(e, stackTrace, "Error loading friends");
      }
  }
  </code></pre>
  
  <p>And in dataService:</p>
  
  <pre><code>Future&lt;List&lt;User&gt;&gt; fetchFriend() async {
      final querySnapshot =
          await _currentUserDoc.reference.collection("friend_requests").getDocuments();
  
      return await Future.wait(querySnapshot.documents.map((doc) async {
        final user = await doc["user"].get();
        User(
          id: user["id"],
          name: user["name"],
        );
      }).toList(growable: false));
    }
  </code></pre>
  
  <p>This is just the last thing that I tried but I tried in so many ways, with Future.wait() too, with/without async/await, etc
  I just can't seem to make it work...</p>