getCurrentVersion method

Future<String> getCurrentVersion()

Returns the currently installed Flutter version as a string.

Attempts to execute flutter --version and parse the result. If it fails or cannot parse the output, returns 'unknown'.

Implementation

Future<String> getCurrentVersion() async {
  try {
    final result = await Process.run('flutter', ['--version']);

    if (result.exitCode != 0) {
      throw Exception('Failed to get Flutter version');
    }

    final output = result.stdout.toString();
    final versionMatch = RegExp(r'Flutter (\S+)').firstMatch(output);

    if (versionMatch != null) {
      return versionMatch.group(1)!;
    }

    throw Exception('Could not parse Flutter version');
  } catch (e) {
    logger.warn('Could not determine current Flutter version: $e');
    return 'unknown';
  }
}