parth shukla
parth shukla

Reputation: 117

Class 'List<DocumentSnapshot>' has no instance method 'call' in Flutter

My firestore database looks something like this enter image description here

What I am trying to do is, I am making a Future list of all the documents with the same uid and then making a ListView using FutureBuilder.

The part giving me the error is,

body: FutureBuilder(
        future: listBuilder(),
        builder: (context, snapshot) {
          if(snapshot.hasData == null){
            return Container();
          }
          return ListView(
            padding: const EdgeInsets.only(top: 20.0),
            children: snapshot.data((data) => _buildListItem(context, data)).toList(),
          );
        },
      ),
Future listBuilder() async {
    final FirebaseUser user = await FirebaseAuth.instance.currentUser();
    final String uid = user.uid;
    List<DocumentSnapshot> list = [];
    Firestore.instance
        .collection('entries')
        .where("uid", isEqualTo: uid)
        .snapshots()
        .listen((data) => data.documents.forEach((doc) => list.add(doc)));

    print("------------------------------------------------------------------");
    return list;
  }
Widget _buildListItem(BuildContext context, DocumentSnapshot snapshot) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: InkWell(
        child: Row(
          children: <Widget>[
            Expanded(
              child: ListTile(
                leading: Text(
                  snapshot.data['type'],
                  style: TextStyle(
                    fontSize: 30,
                  ),
                ),
                title: Text(snapshot.data['description'],
                    style: TextStyle(
                      fontSize: 30,
                    )),
                subtitle: Text(snapshot.data['time'].toDate().toString(),
                    style: TextStyle(
                      fontSize: 15,
                    )),
                trailing: Text(snapshot.data['value'].toString(),
                    style: TextStyle(
                      fontSize: 25,
                    )),
              ), 
            )
          ],
        ),
      ),
    );
  }

Here is the error,

Class 'List<DocumentSnapshot>' has no instance method 'call'.
Receiver: Instance(length:3) of '_GrowableList'
Tried calling: call(Closure: (dynamic) => Widget)

Thank you!

Upvotes: 1

Views: 4137

Answers (1)

Ajay
Ajay

Reputation: 16310

Use the map method.

Like this

     ...
children: snapshot.data.map((data)=>_buildListItem(context,data)).toList(),
     ...

Upvotes: 1

Related Questions