flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.19k stars 26.64k forks source link

Control flow collections: `flutter_tools/` #147450

Closed nate-thegrate closed 1 week ago

nate-thegrate commented 2 weeks ago

This pull request aims for improved readability, based on issue #146600.

// before
List<SupportedPlatform> getSupportedPlatforms({bool includeRoot = false}) {
  final List<SupportedPlatform> platforms = includeRoot
      ? <SupportedPlatform>[SupportedPlatform.root]
      : <SupportedPlatform>[];
  if (android.existsSync()) {
    platforms.add(SupportedPlatform.android);
  }
  if (ios.exists) {
    platforms.add(SupportedPlatform.ios);
  }
  if (web.existsSync()) {
    platforms.add(SupportedPlatform.web);
  }
  if (macos.existsSync()) {
    platforms.add(SupportedPlatform.macos);
  }
  if (linux.existsSync()) {
    platforms.add(SupportedPlatform.linux);
  }
  if (windows.existsSync()) {
    platforms.add(SupportedPlatform.windows);
  }
  if (fuchsia.existsSync()) {
    platforms.add(SupportedPlatform.fuchsia);
  }
  return platforms;
}

// after
List<SupportedPlatform> getSupportedPlatforms({bool includeRoot = false}) {
  return <SupportedPlatform>[
    if (includeRoot)          SupportedPlatform.root,
    if (android.existsSync()) SupportedPlatform.android,
    if (ios.exists)           SupportedPlatform.ios,
    if (web.existsSync())     SupportedPlatform.web,
    if (macos.existsSync())   SupportedPlatform.macos,
    if (linux.existsSync())   SupportedPlatform.linux,
    if (windows.existsSync()) SupportedPlatform.windows,
    if (fuchsia.existsSync()) SupportedPlatform.fuchsia,
  ];
}