importCanonical method
Tries to load the canonicalized canonicalUrl using importer.
If importer can import canonicalUrl, returns the imported Stylesheet.
Otherwise returns null.
If passed, the originalUrl represents the URL that was canonicalized
into canonicalUrl. It's used to resolve a relative canonical URL, which
importers may return for legacy reasons.
Caches the result of the import and uses cached results if possible.
Implementation
Stylesheet? importCanonical(Importer importer, Uri canonicalUrl,
{Uri? originalUrl}) {
return _importCache.putIfAbsent(canonicalUrl, () {
var loadTime = DateTime.now();
var result = importer.load(canonicalUrl);
if (result == null) return null;
_loadTimes[canonicalUrl] = loadTime;
_resultsCache[canonicalUrl] = result;
return Stylesheet.parse(result.contents, result.syntax,
// For backwards-compatibility, relative canonical URLs are resolved
// relative to [originalUrl].
url: originalUrl == null
? canonicalUrl
: originalUrl.resolveUri(canonicalUrl));
});
}