How to create function which return array of widgets
At this time, the following code is deprecated:
List <Widget> gameCells = List<Widget>();
Use the following instead:
List <Widget> gameCells = <Widget>[];
The first code will work anyway, but you will have a warning.
List<Widget> getRandomWidgetArray(){
List <Widget> gameCells = List<Widget>();
for(i=0;i<5;i++)
{
gameCells.add(new MyCellWidget(i));
}
return gameCells;
}
This is the correct way of initializing List, adding elements and returning Widget list.
Array types are List<Type>
in Dart:
List<Widget> getRandomWidgetArray()
[]
can only be used as literal value to create a new list value, not for type declaration.