relative static method

String? relative(
  1. String? path,
  2. Uri? to
)

Implementation

static String? relative(String? path, Uri? to) {
  if (path == null || to == null) {
    return null;
  }
  var fileUri = Uri.parse(path);
  var libName = to.pathSegments.first;
  if ((to.scheme == 'package' &&
          fileUri.scheme == 'package' &&
          fileUri.pathSegments.first == libName) ||
      (to.scheme == 'asset' && fileUri.scheme != 'package')) {
    if (fileUri.path == to.path) {
      return fileUri.pathSegments.last;
    } else {
      return p.posix
          .relative(fileUri.path, from: to.path)
          .replaceFirst('../', '');
    }
  } else {
    return path;
  }
}