I am trying to generate a list of widget after a null check for my object, but I get an error of "Expected an Identifier". The below is my example code:
Column(
children: [
<condition>
? for (var A in <List of object>) <MyWidget>
: const SizedBox(height: 20, width: 20)
],
),
>Solution :
In your code, you’re using an invalid syntax. To fix this issue and achieve your goal, you can use the if statement to conditionally generate widgets within your Column. Here’s an example of how to do this:
Column(
children: [
if (<condition>) ... [
for (var A in <List of object>) ... [
MyWidget(),
],
] else ... [
const SizedBox(height: 20, width: 20),
]
],
)
In this code:
Replace with your actual condition.
Replace with the list of objects you want to iterate over.
Replace with the widget you want to generate for each item in the list.
The if statement is used to conditionally include either the for loop or the SizedBox in the Column based on your condition. Make sure to replace placeholders with your actual code.