findProjectRoot method
Finds and returns the absolute path of the Flutter project root,
starting from startPath (defaults to current directory) and scanning upwards.
Throws ProjectNotFoundException if not found.
Implementation
String findProjectRoot([String? startPath]) {
var current = PathUtils.absolute(startPath ?? '.');
while (true) {
if (_isValidRoot(current)) {
return current;
}
final parent = PathUtils.dirname(current);
if (parent == current) {
break;
}
current = parent;
}
throw ProjectNotFoundException(
'Could not locate a valid Flutter project. '
'Make sure the directory contains a "pubspec.yaml", an "android/" folder, and an "ios/" folder.'
);
}