getImportRelativePath function
Gets the relative import path between two file paths and normalizes it for Dart imports.
Parameters:
Returns:
- A String representing the normalized relative import path from
from
toto
.
Implementation
String getImportRelativePath(String from, String to) {
final raw = path.relative(to, from: from);
final isTrulyUpperLevel = RegExp(r'^\.\./\.\./').hasMatch(raw);
return raw.replaceFirst(RegExp(r'^\.\./'), isTrulyUpperLevel ? '' : './');
}