loadInlineScript function

Future<ScriptElement> loadInlineScript(
  1. String src,
  2. String id, {
  3. String type = 'text/javascript',
})

Include inline ScriptElement inside the

Future

ex: loadInlineScript('console.log("Hello")');

Implementation

Future<ScriptElement> loadInlineScript(
  String src,
  String id, {
  String type = 'text/javascript',
}) {
  var element = document.getElementById(id) as ScriptElement?;

  if (element == null) {
    element = ScriptElement()
      ..type = type
      ..id = id
      ..innerHtml = src;
    document.head!.append(element);
  }
  return waitLoad<ScriptElement>(element);
}