injectHtmlTo method

  1. @override
void injectHtmlTo(
  1. WebHTMLElement parent
)
override

Injects the HTML element into the given parent container.

Implementation

@override
void injectHtmlTo(WebHTMLElement parent) {
  if (!kIsWeb) return;
  final document = webWindow.document;

  // Create a container div to mimic the scroll view
  final divContainer = document.createElement('div') as WebHTMLDivElement;
  divContainer.id = _generateRandomId();

  divContainer.style
    ..overflowY = scrollDirection == Axis.vertical ? 'auto' : 'hidden'
    ..overflowX = scrollDirection == Axis.horizontal ? 'auto' : 'hidden'
    ..maxHeight = '100%'
    ..maxWidth = '100%';

  // Add padding if any
  if (padding != null) {
    final resolved = padding!.resolve(TextDirection.ltr);
    divContainer.style
      ..paddingTop = '${resolved.top}px'
      ..paddingBottom = '${resolved.bottom}px'
      ..paddingLeft = '${resolved.left}px'
      ..paddingRight = '${resolved.right}px';
  }

  // Inject the child widget as HTML
  if (child != null) {
    _appendWidgetToContainer(child!, divContainer);
  }

  parent.appendChild(divContainer);
}