getSdkInfo method

Future<FlutterSdkInfo> getSdkInfo({
  1. String? basePath,
})

Resolves the correct Flutter SDK and fetches its version info.

Implementation

Future<FlutterSdkInfo> getSdkInfo({String? basePath}) async {
  final root = basePath ?? Directory.current.path;

  String executablePath = '';
  bool isFvm = false;
  bool isProjectFvm = false;

  // 1. Check for Project FVM
  final fvmConfigPath = p.join(root, '.fvm', 'fvm_config.json');
  if (File(fvmConfigPath).existsSync()) {
    final fvmSdkPath = p.join(root, '.fvm', 'flutter_sdk', 'bin', _flutterBinName);
    if (!File(fvmSdkPath).existsSync()) {
      throw const ReleaseManagerException(
        'FVM is configured for this project, but the SDK is missing.',
        details: 'Run `fvm install` to download the required Flutter SDK for this project.',
      );
    }
    executablePath = fvmSdkPath;
    isFvm = true;
    isProjectFvm = true;
  } else {
    // 4. Custom executable path from flutter_build_manager.yaml (Checked before System)
    final configPath = p.join(root, 'flutter_build_manager.yaml');
    if (File(configPath).existsSync()) {
      try {
        final doc = loadYaml(File(configPath).readAsStringSync());
        if (doc is YamlMap && doc['release_manager'] is YamlMap) {
          final flutterPath = doc['release_manager']['flutter_path'];
          if (flutterPath != null && flutterPath.toString().isNotEmpty) {
            executablePath = flutterPath.toString();
          }
        }
      } catch (_) {
        // ignore
      }
    }

    if (executablePath.isEmpty) {
      // 2 & 3. Global FVM or System Flutter
      executablePath = 'flutter';
    }
  }

  return _validateAndFetchInfo(executablePath, isFvm: isFvm, isProjectFvm: isProjectFvm);
}