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
I fixed it by iterating through the array in cloud firestore and adding each item to my list. Here's the code:
It seems there is probably an easier way to pull it, but I tried
cast
,toList
and many other methods. Just got different errors.toList
is a function, so you need to invoke it by adding()
after it