checkFlutterInstallation method

Future<bool> checkFlutterInstallation()

Implementation

Future<bool> checkFlutterInstallation() async {
  try {
    final result = await Process.run('flutter', ['--version']);
    if (result.exitCode == 0) return true;
  } catch (_) {}

  try {
    if (Platform.isWindows) {
      final whereRes = await Process.run('where', ['flutter']);
      if (whereRes.exitCode == 0 &&
          whereRes.stdout.toString().trim().isNotEmpty) {
        return true;
      }
    } else {
      final whichRes = await Process.run('which', ['flutter']);
      if (whichRes.exitCode == 0 &&
          whichRes.stdout.toString().trim().isNotEmpty) {
        return true;
      }
    }
  } catch (_) {}

  final pathEnv =
      Platform.environment['PATH'] ?? Platform.environment['Path'] ?? '';
  final separator = Platform.isWindows ? ';' : ':';
  final entries = pathEnv.split(separator);
  for (var entry in entries) {
    final trimmed = entry.trim();
    if (trimmed.isEmpty) continue;

    final candidate1 = Platform.isWindows
        ? File('$trimmed\\flutter.bat')
        : File('$trimmed/flutter');

    if (candidate1.existsSync()) return true;

    final candidate2 = File(
      '${trimmed}${Platform.pathSeparator}bin${Platform.pathSeparator}flutter${Platform.isWindows ? '.bat' : ''}',
    );
    if (candidate2.existsSync()) return true;
  }

  return false;
}