ciFlutterExecutable function
FLUTTER_ROOT's flutter, else the SDK this Dart belongs to, else PATH,
else null.
Implementation
String? ciFlutterExecutable({Map<String, String>? environment}) {
final env = environment ?? Platform.environment;
final name = Platform.isWindows ? 'flutter.bat' : 'flutter';
final root = env['FLUTTER_ROOT'];
if (root != null && File(p.join(root, 'bin', name)).existsSync()) {
return p.join(root, 'bin', name);
}
// <flutter>/bin/cache/dart-sdk/bin/dart
final dartBin = p.dirname(Platform.resolvedExecutable);
final fromDart = p.normalize(p.join(dartBin, '..', '..', '..', name));
if (File(fromDart).existsSync()) return fromDart;
for (final dir in (env['PATH'] ?? '').split(Platform.isWindows ? ';' : ':')) {
if (dir.isEmpty) continue;
final candidate = p.join(dir, name);
if (File(candidate).existsSync()) return candidate;
}
return null;
}