How to add 4 children or some cases it will be 3 or 2 to the column in the flutter.
Column(
children: <Widget>[_weatherData],
)
If you want to add Widget dynamically,
List<Widget> data() {
List<Widget> list = List();
//i<5, pass your dynamic limit as per your requirment
for (int i = 0; i < 5; i++) {
list.add(Text("Index $i"));//add any Widget in place of Text("Index $i")
}
return list;// all widget added now retrun the list here
}
Now add this list into your column,
Column(
mainAxisSize: MainAxisSize.max,
children: data(),
),
OutPut:
If you know beforehand which Widgets you want to add, you can use inline if
statements when building the children:
Column(
children: <Widget>[
if(condition1)
widget1,
if(condition2)
widget2,
_ weatherData,
],)
or if you do not know beforehand, you can call a function there that returns a List<Widget>
.
Using the spread operator (...
) you can even mix and match:
Column(
children: <Widget>[
if(condition1)
widget1,
if(condition2)
widget2,
_ ..._getWeatherDataWidgets(),
],)
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With