prefer_for_elements_to_map_fromIterable

Group: style

Maturity: stable

Dart SDK: >= 2.2.1-dev.4.0 • (Linter v0.1.85)

Since info is static, may be stale
pedantic

View all Lint Rules

Using the Linter

When building maps from iterables, it is preferable to use for elements.

BAD:

Map<String, WidgetBuilder>.fromIterable(
  kAllGalleryDemos,
  key: (demo) => '${demo.routeName}',
  value: (demo) => demo.buildRoute,
);

GOOD:

return {
  for (var demo in kAllGalleryDemos)
    '${demo.routeName}': demo.buildRoute,
};