I'm trying to get a List<dynamic'> _list but since I upgraded flutter to 2.0, I had to change my code to _list(QuerySnapshot<Map<String, dynamic>> snapshot). that type don't have length, or elementAt like normal List<dynamic'> type. it is possible to convert it?
my code:
List _list(QuerySnapshot<Map<String, dynamic>> snapshot) {
return snapshot.docs
.map((doc) => new Brand(
doc.data()['brandId'].toString(),
))
.toList();
}
later on my code I need use some fields:
return StaggeredGridView.countBuilder(
itemCount: _list.length,
itemBuilder: (BuildContext context, int index) {
Brand brand = _list.elementAt(index) as Brand;
return InkWell(
onTap: () {
Navigator.of(context).pushNamed('/Brand',
arguments: new RouteArgument(
id: _list[index].id)
the error message: error: The operator '[]' isn't defined for the type 'List Function(QuerySnapshot<Map<String, dynamic>>)'
any ideas are welcome, thank's in advance!
as of now your
_list
is defined as aFunction
that returns aList
rather than being aList
itself.So, in order to use it, you should firstly properly
call
it with the necessary parameter.Like this,