title: Flutter how to group a list from firebase based on a certain value
body: <p>I have a firebase database with 2 relevant collections: "products" and "categories".</p>
  
  <p>I would like to show the products in a listview grouped by their category.</p>
  
  <p>In every product document there is a 'category' field which is the category id.</p>
  
  <p>Right now I have this code to just create the listview:</p>
  
  <pre><code>StreamBuilder(
      stream: Firestore.instance.collection('products').snapshots(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) return const Text("Loading...");
        return ListView.builder(
          itemBuilder: (context, index) =&gt; buildProductItem(context, snapshot.data.documents[index]),
          itemCount: (snapshot.data.documents.length),
        );
      }
  )
  </code></pre>
  
  <p>I've tried a few things (like this: <a href="https://stackoverflow.com/questions/60178292/flutter-how-to-create-a-list-with-header-from-a-firebase-object">question</a>), but I want to keep it within the StreamBuilder so the data will still update live.</p>
  
  <p>How would I group them so I can show a title above every group and the products corresponding to that title underneath?</p>