posixRelativeImportUri static method

String posixRelativeImportUri({
  1. required String fromFile,
  2. required String toFile,
})

Dart import URI from fromFile to toFile, both app-root relative.

Implementation

static String posixRelativeImportUri({
  required String fromFile,
  required String toFile,
}) {
  final fromDir = p.posix.dirname(fromFile.replaceAll('\\', '/'));
  final relative = p.posix.relative(
    p.posix.normalize(toFile.replaceAll('\\', '/')),
    from: fromDir,
  );
  return relative.startsWith('.') ? relative : './$relative';
}