lxknvlk
lxknvlk

Reputation: 2850

Flutter - how to add list of widgets to column element?

Let's say we have a column. Is it possible to add several widgets using one method? Something like .addAll()?

Column(
  children: [
    SomeWidget(),
    _someBigWidgetMethod(),
    _severalWidgets(),
  ]
)

_severalWidgets(){
  return [
    Widget(),
    Widget(),
    Widget(),
  ];
}

Upvotes: 3

Views: 3448

Answers (1)

h8moss
h8moss

Reputation: 5020

In order to add all items in a list into another list, you can use the ... operator:

List<Widget> _myMethod() => [Widget1(), Widget2(), Widget3(), Widget4()];

Widget build(BuildContext context) {
  return Column(
    children: [
      SomeWidget(),
      ..._myMethod(),
    ]
  );
}

Upvotes: 13

Related Questions