skip to Main Content

I’m trying to pull data from a cloud firestore database using a StreamBuilder and assign it to a List in Flutter. The code below gives the error:

_TypeError (type ‘({bool growable}) => List’ is not a subtype of type ‘List’)

    return ListView(
      children: snapshot.data!.docs
          .map((DocumentSnapshot document) {
            Map<String, dynamic> data =
                document.data()! as Map<String, dynamic>;
                List<dynamic> listUsers = data['usersLiked'].toList;

usersLiked is an array of strings in the database.

I reviewed similar questions in stackoverflow but they don’t seem to be the same and I haven’t been able to modify this code so that I can just pull the data from the firestore database and put it into the list. Any help would be appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed it by iterating through the array in cloud firestore and adding each item to my list. Here's the code:

    List<String> listUsers = [];
       for (int i = 0; i < data['usersLiked'].length; i++) {
       listUsers.add(data['usersLiked'][i]);
       }
    

    It seems there is probably an easier way to pull it, but I tried cast, toList and many other methods. Just got different errors.


  2. toList is a function, so you need to invoke it by adding () after it

    List<dynamic> listUsers = data['usersLiked'].toList();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search