How to spread a list in dart
You can now do spreading from Dart 2.3
var a = [0,1,2,3,4];
var b = [6,7,8,9];
var c = [...a,5,...b];
print(c); // prints: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
There is an issue to add this to future version of dart https://github.com/dart-lang/language/issues/47
but for now you can use sync*
and yield*
Iterable<Widget> _buildChildren sync* {
yield MyHeader();
yield* _buildListOfWidgetForBody();
yield MyCustomFooter();
}
EDIT: As of Dart 2.3 you can now do:
Widget build(BuildContext context) {
return Column(
children: <Widget>[
MyHeader(),
..._buildListOfWidgetForBody(),
MyCustomFooter(),
],
);
}