I am working on a question application. I am trying to create a list in order to put icons in it so that if the person answers the question, the result of the answer will appear, but I saw this error inside the row!!!
**The argument type ‘List’ can’t be assigned to the parameter type ‘List’.dartargument_type_not_assignable **
-> this is the code
class exampage extends StatefulWidget {
const exampage({Key? key}) : super(key: key);
@override
State<exampage> createState() => _exampageState();
}
class _exampageState extends State<exampage> {
List answerResult = [
Padding(
padding: const EdgeInsets.all(3.0),
child: Icon(
Icons.check,
color: Color.fromARGB(255, 27, 135, 76),
),
),
Padding(
padding: const EdgeInsets.all(3.0),
child: Icon(
Icons.close,
color: Color.fromARGB(255, 223, 84, 75),
),
),
];
@override
Widget build(BuildContext context) {
return Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Row(
children: answerResult,
),
Isn’t everything correct, what’s the problem with the error?
what should I try ?
2
Answers
I find the solution if you have the same error just add
<Widget>
after listlike this :
Just Explaining @Balkis’s Answer:
To resolve this issue, specify the type of the List when you declare answerResult. If you do not specify the type of a List in dart it is considered as dynamic type. So change:
to:
With this change, you’re explicitly telling Dart that answerResult is a List of Widgets, and you shouldn’t encounter the error when you use it in the Row’s children.