'Flutter how to use Lists to create similar widgets white implicit-case and implicity-dynamic set to false
I'm trying to be better about typing in flutter/dart. To force this, I made an analysis_options.yaml with:
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
and that works great, but I have a hard time with code like the following:
Widget build(BuildContext context) {
return Column(
children: [...widgetList()]);
}
widgetList(){
List<Map<String,dynamic>> defineWidgets = [
{"text":"beer", "color": Colors.blue}, // <-- Missing type arguments for map literal. Try adding an explicit type like 'dynamic' or enable implicit dynamic in your analysis options.
{"text":"wine", "color": Colors.red},
];
List<Widget> finalWidgets =[];
for(int i = 0; i < defineWidgets.length; i++ ){
finalWidgets.add(
Expanded(child:Container(
child:Text(defineWidgets[i]['text']), // <-- the argument type 'dynamic' can't be assigned to the parameter type 'String'
color:defineWidgets[i]['color']
))
);
}
return finalWidgets;
}
I tried using cast() to no avail. Is there a way to do this of function without setting implicit-casts and implicit-dynamic to true?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
