functional-programmingdartflutter

Dart: mapping a list (list.map)


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.


Solution

  • 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()
          ,
        ),