restoreAbsolute method

  1. @override
Uri restoreAbsolute(
  1. Source source
)

Return an absolute URI that represents the given source, or null if a valid URI cannot be computed.

The computation should be based solely on source.fullName.

Implementation

@override
Uri restoreAbsolute(Source source) {
  String sourcePath = source.fullName;
  pathos.Context pathContext = resourceProvider.pathContext;
  for (String pkgName in packageMap.keys) {
    Folder pkgFolder = packageMap[pkgName][0];
    String pkgFolderPath = pkgFolder.path;
    if (sourcePath.startsWith(pkgFolderPath + pathContext.separator)) {
      String relPath = sourcePath.substring(pkgFolderPath.length + 1);
      List<String> relPathComponents = pathContext.split(relPath);
      String relUriPath = pathos.posix.joinAll(relPathComponents);
      return Uri.parse('$PACKAGE_SCHEME:$pkgName/$relUriPath');
    }
  }
  return null;
}