Uchenna Ndukwe
Uchenna Ndukwe

Reputation: 71

The operator '[]' isn't defined for the class 'Map<String, dynamic> Function()'

i am trying to load this data from firebase:

Widget BlogList() {
return Container(
  child: Column(
    children: [
      blogSnapshot != null ? ListView.builder(
        itemCount: blogSnapshot.docs.length,
        shrinkWrap: true,
        itemBuilder: (context, index){
          return BlogTile(
            authorName: blogSnapshot.docs[index].data['authorName'],
            title: blogSnapshot.docs[index].data['title'],
            description: blogSnapshot.docs[index].data['description'],
            imgUrl: blogSnapshot.docs[index].data['imgUrl'],
          );
        },
      ): Container(
        alignment: Alignment.center,
        child: CircularProgressIndicator(),)
    ],
  ),
);

}

but i am getting this error:

    Error: The operator '[]' isn't defined for the class 'Map<String, dynamic> Function()'.
 - 'Map' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
                authorName: blogSnapshot.docs[index].data['authorName'],
                                                         ^

pls have me out here with this error

Upvotes: 0

Views: 514

Answers (2)

Mir Moktadir
Mir Moktadir

Reputation: 11

Do this:

itemBuilder: (context, index){
          return BlogTile(
            authorName: blogSnapshot.docs[index].data()['authorName'],
            title: blogSnapshot.docs[index].data()['title'],
            description: blogSnapshot.docs[index].data()['description'],
            imgUrl: blogSnapshot.docs[index].data()['imgUrl'],
          );

Upvotes: 1

Randal Schwartz
Randal Schwartz

Reputation: 44186

I'm guessing that somewhere in that chain (like data) is a function, and needs invoking by adding (). Use your IDE to verify the type of data.

Upvotes: 0

Related Questions