Dart: mapping a list (list.map)

AbdulMomen عبدالمؤمن picture AbdulMomen عبدالمؤمن · Apr 20, 2018 · Viewed 102.2k times · Source

I have a list of Strings, e.g.,

var moviesTitles = ['Inception', 'Heat', 'Spider Man'];

and wanted to use moviesTitles.map to convert them to a list of Tab Widgets in Flutter.

Answer

you can use

moviesTitles.map((title) => Tab(text: title)).toList()

example:

    bottom: new TabBar(
      controller: _controller,
      isScrollable: true,
      tabs:
        moviesTitles.map((title) => Tab(text: title)).toList()
      ,
    ),