0

I would like to create several containers in a scaffold.

Do I have to create them manually or can I reduce the code by using an if with counter statement to generate them?

If I can use an if statement could you provide a simple example?

Thanks.

2
  • The real question is WHYYY. I would advise you to go through some tutorials or courses that explain how widget tree works Commented Nov 29, 2020 at 17:03
  • although you asked a valid question, please add some context or scenario Commented Nov 30, 2020 at 6:28

1 Answer 1

1

This is pretty vague. It really depends on what you need. But yes, you can use if() and even for() in the widget tree. Here is an example for each of them :

// State variable
var list = ["first", "second"];

// in build() method
if(list.isNotEmpty)
  Container()

Column(children: [
  for(var item in list)
    Container(child: Text(item))
])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.