switchVersion method

Future<void> switchVersion(
  1. String version
)

Switches the Flutter SDK to the specified version.

  • If FVM is available, it uses FVM to manage and install versions.
  • Otherwise, it attempts to use the Flutter SDK directly.
  • Supports both channel names (e.g., stable, beta) and specific version tags (e.g., 3.16.0).

Implementation

Future<void> switchVersion(String version) async {
  final currentVersion = await getCurrentVersion();
  logger.info('Requested Flutter version: $version');
  logger.info('Current Flutter version: $currentVersion');

  if (version == currentVersion) {
    logger.info('Already using Flutter $version');
    return;
  }

  final fvmAvailable = await _isFvmAvailable();

  if (fvmAvailable) {
    await _switchWithFvm(version);
  } else {
    await _switchWithFlutterSdk(version);
  }
}