'Reading a Firestore Map into a ListView in Flutter

I have a DB that looks like this:

enter image description here

I am trying to read the Leaderboard entries and put them inside a ListView but stuck at the moment

        builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
      if (snapshot.hasData) {
        var snapDocument = snapshot.data?.data;
        var entries = snapDocument['entries'];
        return Scaffold(
          body: Stack(children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: ListView.builder(
                    physics: const BouncingScrollPhysics(),
                    itemBuilder: (context, int index) {
                      return LeaderboardCard(
                        currentScore: entries[index]['score'].toString(),
                        name: entries[index]['name'],
                        index: index,
                        isCurrentUser: entries[index]['uid'] == user!.uid,
                      );
                    },
                    itemCount: entries.length,
                  ),

Here is the initState as well

  late final Stream<DocumentSnapshot> _mainScoreStream;

  @override
  void initState() {
    futureAd = fetchAd();
    _mainScoreStream = FirebaseFirestore.instance
        .collection('leaderboard')
        .doc('leaderboard_id')
        .snapshots();
    super.initState();
  }


Solution 1:[1]

You should not be able to write its categoryId, but you need a getter and a setter for Product.category. To change the category of a product, you would do product.setCategory(newCategory). If you want to READ the category ID of a product, you also need to add a getter for Category.id; you would then do: product.getCategory().getId().

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Maurice Perry