I have a list of String
s, e.g.,
var moviesTitles = ['Inception', 'Heat', 'Spider Man'];
and wanted to use moviesTitles.map
to convert them to a list of Tab
Widget
s in Flutter.
This question is related to
functional-programming
dart
flutter
Yes, You can do it this way too
List<String> listTab = new List();
map.forEach((key, val) {
listTab.add(val);
});
//your widget//
bottom: new TabBar(
controller: _controller,
isScrollable: true,
tabs: listTab
,
),
tabs: [...data.map((title) { return Text(title);}).toList(), extra_widget],
tabs: data.map((title) { return Text(title);}).toList(),
It's working fine for me
I'm new to flutter. I found that one can also achieve it this way.
tabs: [
for (var title in movieTitles) Tab(text: title)
]
Note: It requires dart sdk version to be >= 2.3.0, see here
I try this same method, but with a different list with more values in the function map. My problem was to forget a return statement. This is very important :)
bottom: new TabBar(
controller: _controller,
isScrollable: true,
tabs:
moviesTitles.map((title) { return Tab(text: title)}).toList()
,
),
Source: Stackoverflow.com