I cannot get the length of all the elements in my list because it contains Widgets. Is there a way I can get around this? I use
to generate the list with the element lengths.
I'm getting the following error: The element type 'List<Container>' can't be assigned to the list type 'Widget'.dartlist_element_type_not_assignable
.
This is an example of the contents list I'm trying to get the length from:
I've tried list builder instead of list generator but this doesn't seem to make a difference.
CodePudding user response:
Add spread operator at the front if the List
, and use the length
on the List
normally.
children: [
...List.generate(contents.length, (index) => buildDot(index, context)), // add ... like this in your List
],
this will lead that your list will be merged with the principal list.