The element type 'Set<Widget?>' can't be assigned to the list type 'Widget'

Issue

I am using Flutter, and trying to show Image asset (question.answerImage) if it is not null.
I wrote a code as follows, but it returns an error.

...
content: Column(children: [
             if (question.answerImage!=null){question.answerImage},
             ...

Error is written as follows:

The element type ‘Set<Widget?>’ can’t be assigned to the list type ‘Widget’.

How can I change the type Set<Widget?> to type Widget?

Best Regards,

Solution

You are using if/else statements in Collection literals.

Remove the curly braces.

...
content: Column(children: [
         if (question.answerImage!=null)question.answerImage,
         ...

Answered By – Raju Gupta

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *