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,
CodePudding user response:
You are using if/else statements in Collection literals.
Remove the curly braces.
...
content: Column(children: [
if (question.answerImage!=null)question.answerImage,
...
CodePudding user response:
If there is some widget other than 'question.answerImage',
you need to use 'spread operator' to seperate List to each Widget.
https://www.woolha.com/tutorials/dart-using-triple-dot-spread-operator-examples
[Example]
Column(children: [
...question.answerIamge,
Container(...),
Row(...),
]
)
...
content: Column(children: [
if (question.answerImage!=null)...question.answerImage,
...