Control flow collections: flutter_tools/ (#147450)

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

```dart
// 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,
  ];
}
```
This commit is contained in:
Nate
2024-05-02 16:19:18 -06:00
committed by GitHub
parent 7436cc25eb
commit 5d1bfdcb87
26 changed files with 219 additions and 457 deletions

View File

@@ -384,17 +384,12 @@ class AndroidStudio {
final String? homeDirPath = globals.fsUtils.homeDirPath;
if (homeDirPath != null && globals.fs.directory(homeDirPath).existsSync()) {
final Directory homeDir = globals.fs.directory(homeDirPath);
final List<Directory> directoriesToSearch = <Directory>[homeDir];
// >=4.1 has new install location at $HOME/.cache/Google
final String cacheDirPath =
globals.fs.path.join(homeDirPath, '.cache', 'Google');
if (globals.fs.isDirectorySync(cacheDirPath)) {
directoriesToSearch.add(globals.fs.directory(cacheDirPath));
}
final String cacheDirPath = globals.fs.path.join(homeDirPath, '.cache', 'Google');
final List<Directory> directoriesToSearch = <Directory>[
globals.fs.directory(homeDirPath),
if (globals.fs.isDirectorySync(cacheDirPath)) globals.fs.directory(cacheDirPath),
];
final List<Directory> entities = <Directory>[];

View File

@@ -811,14 +811,11 @@ class AndroidGradleBuilder implements AndroidBuilder {
_logger.printError(result.stderr, wrap: false);
return const <String>[];
}
final List<String> options = <String>[];
for (final String line in LineSplitter.split(result.stdout)) {
final RegExpMatch? match = _kBuildVariantRegex.firstMatch(line);
if (match != null) {
options.add(match.namedGroup(_kBuildVariantRegexGroupName)!);
}
}
return options;
return <String>[
for (final String line in LineSplitter.split(result.stdout))
if (_kBuildVariantRegex.firstMatch(line) case final RegExpMatch match)
match.namedGroup(_kBuildVariantRegexGroupName)!,
];
}
@override