Reputation: 121
I face this issue if I want to print two lists in a column in Flutter. As you know, we can print a list in column like below:
Column(
children:List.generate(list1.length, (index)=>
// some widgets here
),
)
But how can I generate it from two lists like below:
Column(
children:<Widget> [
// some widgets here,
List.generate(list1.length, (index)=>
// some widgets here
),
List.generate(list2.length, (index)=>
// some widgets here
),
// some widgets here,
]
)
Upvotes: 0
Views: 876
Reputation: 2386
You can use the spread operator for that:
Column(
children: [
some widgets here,
...List.generate(list1.length, (index)=>
// some widgets here
),
...List.generate(list2.length, (index)=>
// some widgets here
),
// some widgets here,
]
)
Prior to 2.3.0 when the collections operators were introduced, you'd have to do this manually:
Column(
children: [/* First widgets */]
..addAll(List.generate(...))
..addAll(List.generate(...)),
)
Upvotes: 3