injectHtmlTo method
Injects the HTML element into the given parent container.
Implementation
@override
void injectHtmlTo(WebHTMLElement parent) {
if (!kIsWeb) return;
// Create a container for the grid
final gridContainer =
webWindow.document.createElement('div') as WebHTMLElement;
gridContainer.style.display = 'grid';
gridContainer.style.overflow = 'auto';
// Try to infer column count if it's a SliverGridDelegateWithFixedCrossAxisCount
if (gridDelegate is SliverGridDelegateWithFixedCrossAxisCount) {
final count =
(gridDelegate as SliverGridDelegateWithFixedCrossAxisCount)
.crossAxisCount;
gridContainer.style.gridTemplateColumns =
'repeat($count, minmax(0, 1fr))';
} else {
// Fallback: auto-fill with min column width
gridContainer.style.gridTemplateColumns =
'repeat(auto-fill, minmax(100px, 1fr))';
}
// Inject each child widget
for (final child in children) {
if (child is SeoInjectable) {
final element = (child as SeoInjectable).createHtmlElement();
if (element != null) {
gridContainer.appendChild(element);
}
} else if (child is SeoInjectableLayout) {
(child as SeoInjectableLayout).injectHtmlTo(gridContainer);
}
}
// Append the container to the parent
parent.appendChild(gridContainer);
}