From a541934125fa2240f2943c94b1c32fde95857cc9 Mon Sep 17 00:00:00 2001 From: Alexandre Ardhuin Date: Wed, 8 Jan 2020 17:03:02 +0100 Subject: [PATCH] enable lint prefer_for_elements_to_map_fromIterable (#47726) --- analysis_options.yaml | 2 +- examples/flutter_gallery/lib/gallery/app.dart | 8 +++----- examples/flutter_gallery/lib/gallery/demos.dart | 10 ++++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 5c20c572edb3c..d471f30c9a0a6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -143,7 +143,7 @@ linter: - prefer_final_fields - prefer_final_in_for_each - prefer_final_locals - # - prefer_for_elements_to_map_fromIterable # not yet tested + - prefer_for_elements_to_map_fromIterable - prefer_foreach # - prefer_function_declarations_over_variables # not yet tested - prefer_generic_function_type_aliases diff --git a/examples/flutter_gallery/lib/gallery/app.dart b/examples/flutter_gallery/lib/gallery/app.dart index 5afc8bd27e33a..228d3c56fdbad 100644 --- a/examples/flutter_gallery/lib/gallery/app.dart +++ b/examples/flutter_gallery/lib/gallery/app.dart @@ -51,11 +51,9 @@ class _GalleryAppState extends State { // For a different example of how to set up an application routing table // using named routes, consider the example in the Navigator class documentation: // https://docs.flutter.io/flutter/widgets/Navigator-class.html - return Map.fromIterable( - kAllGalleryDemos, - key: (dynamic demo) => '${(demo as GalleryDemo).routeName}', - value: (dynamic demo) => (demo as GalleryDemo).buildRoute, - ); + return { + for (final GalleryDemo demo in kAllGalleryDemos) demo.routeName: demo.buildRoute, + }; } @override diff --git a/examples/flutter_gallery/lib/gallery/demos.dart b/examples/flutter_gallery/lib/gallery/demos.dart index f12f3098fdb68..979dc7aa342ce 100644 --- a/examples/flutter_gallery/lib/gallery/demos.dart +++ b/examples/flutter_gallery/lib/gallery/demos.dart @@ -579,9 +579,7 @@ final Map> kGalleryCategoryToDemos = }, ); -final Map kDemoDocumentationUrl = - Map.fromIterable( - kAllGalleryDemos.where((GalleryDemo demo) => demo.documentationUrl != null), - key: (dynamic demo) => (demo as GalleryDemo).routeName, - value: (dynamic demo) => (demo as GalleryDemo).documentationUrl, - ); +final Map kDemoDocumentationUrl = { + for (final GalleryDemo demo in kAllGalleryDemos) + if (demo.documentationUrl != null) demo.routeName: demo.documentationUrl, +};