getFlutterBinary method
Implementation
@visibleForTesting
String getFlutterBinary() {
// FLUTTER_ROOT can be set by Dart-Code VSCode extension or dart shell
// script shipped with flutter sdk.
var flutterRoot = Platform.environment['FLUTTER_ROOT'];
if (flutterRoot == null) {
// Attempt to find flutter root from dart binary path.
final dartPathSegments = path.split(Platform.resolvedExecutable);
final flutterFolderSegmentIndex = dartPathSegments.lastIndexOf('flutter');
if (flutterFolderSegmentIndex != -1 &&
dartPathSegments[flutterFolderSegmentIndex + 1] == 'bin') {
flutterRoot = path.joinAll(
dartPathSegments.sublist(0, flutterFolderSegmentIndex + 1),
);
}
}
if (flutterRoot == null) {
// Fallback to use flutter from PATH.
return Platform.isWindows ? 'flutter.bat' : 'flutter';
}
return path.join(
flutterRoot,
'bin',
Platform.isWindows ? 'flutter.bat' : 'flutter',
);
}