loadLink function

Future<LinkElement> loadLink(
  1. String href, {
  2. String? id,
  3. String rel = 'stylesheet',
  4. String type = 'text/css',
})

Include a LinkElement inside the

Future

ex: loadLink('./style.css');

Implementation

Future<LinkElement> loadLink(
  String href, {
  String? id,
  String rel = 'stylesheet',
  String type = 'text/css',
}) {
  var element = id != null
      ? document.getElementById(id) as LinkElement?
      : document.querySelector("link[href='$href']") as LinkElement?;

  if (element == null) {
    element = LinkElement()
      ..type = type
      ..rel = rel
      ..href = href;
    if (id != null) {
      element.id = id;
    }
    document.head!.append(element);
  }

  return waitLoad<LinkElement>(element);
}