skip to Main Content

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


  1. Chosen as BEST ANSWER

    I find the solution if you have the same error just add <Widget> after list

    like this :

    List<Widget> 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),
      ),
    ),
    ];
    

  2. 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:

    List answerResult = [
    

    to:

    List<Widget> answerResult = [
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search