addCSSCode function

Future<bool> addCSSCode(
  1. String cssCode
)

Adds a CSS code (cssCode) into DOM.

Implementation

Future<bool> addCSSCode(String cssCode) async {
  var prevCall = _addedCSSCodes[cssCode];
  if (prevCall != null) return prevCall;

  Future<bool> future;

  try {
    var head = querySelector('head') as HeadElement;

    var styleElement = StyleElement();
    styleElement.innerHtml = cssCode;

    head.append(styleElement);

    future = Future.value(true);
  } catch (e, s) {
    print(e);
    print(s);
    future = Future.value(false);
  }

  _addedCSSCodes[cssCode] = future;

  return future;
}