Flutter Firestore: The operator '[]' isn't defined for the class 'Object?'. – 'Object' is from 'dart:core'

0

Issue

I tried a number of things, and it keeps on showing errors:

children: snapshot.data!.docs.map((document) {
                final data = document.data()! as Map<String, dynamic>;
                print(data);
                return ProductCard(
                  title: Text(data["name"]),
                  imageUrl: document.data()['images'][0],
                  price: "\$${document.data()['price']}",
                  productId: document.id, onPressed: (){},
                );
              }).toList(),
            );

Solution

it’s my mistake the correct solution is:

children: snapshot.data!.docs.map((document) {
                final data = document.data()! as Map<String, dynamic>;
                print(data);
                return ProductCard(
                  title: "${data["name"]}",
                  imageUrl: data['images'][0],
                 // price: "\$${data['price']}",
                  productId: document.id, onPressed: (){},
                );
              }).toList(),

Answered By – Divyanshu Khattar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More