getFlutterVersion method

Future<String> getFlutterVersion()

Implementation

Future<String> getFlutterVersion() async {
  try {
    final result = await Process.run('flutter', ['--version']);
    if (result.exitCode != 0) {
      throw ProcessException('flutter', ['--version'], 'Flutter command returned exit code ${result.exitCode}', result.exitCode);
    }
    final stdout = result.stdout as String;
    final firstLine = stdout.split('\n').firstWhere((line) => line.trim().isNotEmpty, orElse: () => '');
    if (firstLine.isEmpty) {
      throw const FormatException('Flutter version output was empty.');
    }
    final parts = firstLine.split('•');
    return parts.first.trim();
  } catch (e) {
    throw Exception('Flutter SDK is not available or returned an error: $e');
  }
}