createStyleSheet function

CSSStyleSheet createStyleSheet(
  1. String cssText
)

Creates or retrieves a cached web.CSSStyleSheet from the given CSS string.

This function uses the constructable stylesheets API which is more efficient than creating <style> elements. Stylesheets are cached so the same CSS content always returns the same instance.

Implementation

web.CSSStyleSheet createStyleSheet(String cssText) {
  return _stylesheetCache.putIfAbsent(cssText, () {
    final sheet = web.createCSSStyleSheet();
    sheet.replaceSync(cssText);
    return sheet;
  });
}