findPackagePath function
Find our package path in the current project
Implementation
String? findPackagePath(String currentPath, {bool? windows}) {
String? findPath(File file) {
var lines = LineSplitter.split(file.readAsStringSync());
for (var line in lines) {
var parts = line.split(':');
if (parts.length > 1) {
if (parts[0] == 'sqflite_common_ffi') {
var location = parts.sublist(1).join(':');
return absolute(normalize(
toFilePath(dirname(file.path), location, windows: windows)));
}
}
}
return null;
}
var file = File(join(currentPath, '.packages'));
if (file.existsSync()) {
return findPath(file);
} else {
var parent = dirname(currentPath);
if (parent == currentPath) {
return null;
}
return findPackagePath(parent);
}
}