others static method

List<({FlutterSdk sdk, String source})> others({
  1. Map<String, String>? environment,
})

The Flutter SDKs on this machine besides the ones just installed: FLUTTER_ROOT's, the one flutter on the PATH is, and fvm's — each once, with where it was found.

Implementation

static List<({FlutterSdk sdk, String source})> others({
  Map<String, String>? environment,
}) {
  final env = environment ?? Platform.environment;
  final found = <String, ({FlutterSdk sdk, String source})>{};
  void add(String? root, String source) {
    if (root == null || root.isEmpty) return;
    final sdk = FlutterSdk(root);
    if (!sdk.exists || found.containsKey(sdk.root)) return;
    found[sdk.root] = (sdk: sdk, source: source);
  }

  add(env['FLUTTER_ROOT'], 'FLUTTER_ROOT');
  add(_fromPath(env), 'PATH');
  for (final fvm in _fvmFolders(env)) {
    final versions = Directory('$fvm/versions');
    try {
      if (!versions.existsSync()) continue;
      for (final d in versions.listSync().whereType<Directory>()) {
        add(d.path, 'fvm');
      }
    } on FileSystemException {
      // An fvm folder that can't be read: nothing found there.
    }
  }
  return found.values.toList();
}