createHtmlElement method

  1. @override
WebHTMLElement? createHtmlElement()
override

Creates and returns a WebHTMLElement to represent this object in the DOM.

Returns null if no element should be created.

Implementation

@override
WebHTMLElement? createHtmlElement() {
  if (!kIsWeb) return null;
  final element =
      WebHTMLImageElement()
        ..src = src
        ..alt = alt ?? semanticLabel ?? ''
        ..id = id ?? _generateRandomId();

  if (width != null) element.width = width!.toInt();
  if (height != null) element.height = height!.toInt();
  return element;
}