'How to make a list view widget out of a firestore array

I am trying to display my Cart data from firestore into a listview widget but to do so, I need the 'Cart' array's length.

Firestore Database Structure

How do I build a listview on my app based on the data from the 'Cart' collection?

child: StreamBuilder(
    stream: FirebaseFirestore.instance
        .collection('Users')
        .doc(user.uid)
        .collection('Cart')
        .snapshots(),
    builder: (context, AsyncSnapshot snapshot) {
      if (!snapshot.hasData)
        return Center(child: CircularProgressIndicator());
      else
        return Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ListView.separated(
                  shrinkWrap: true,
                  itemBuilder: (context, index) => Cartproductcard(
                        cartItem: snapshot.data[index],
                      ),
                  separatorBuilder: (context, _) =>
                      SizedBox(width: 12),
                  itemCount: snapshot.data
                      .length() 
              ),

This is what I am am left with so far, when I tried to run it I got the error:

"NoSuchMethodError (NoSuchMethodError: Class '_JsonQuerySnapshot' has no instance method 'length'. Receiver: Instance of '_JsonQuerySnapshot' Tried calling: length())"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source