Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]' error in stream builder

I am getting following error: The operator ‘[]’ isn’t defined for the type ‘Object’.
Try defining the operator ‘[]’
The part where error is coming is highlighted here

The code for stream is this

StreamBuilder(
                stream: FirebaseFirestore.instance
                    .collection('Users')
                    .doc(FirebaseAuth.instance.currentUser?.uid)
                    .collection('Coins')
                    .snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (!snapshot.hasData) {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  }
                  return ListView(

                    children: snapshot.data!.docs.map((document) {
                      return Container(
                        
                        child: Row(
                          children: [
                            
                            Text("Coin type: ${document.id}"),
                            
                            Text("Amount Owned: ${document.data()!['Amount']}"),
                          ],
                        ),
                      );
                    }).toList(),
                  );
                }),

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use as Map?

Text(
    "Amount Owned: ${(document.data() as Map?)?['Amount']}"),

More about dart and reading data from firestore.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading