buildWebNativeImage function

Widget buildWebNativeImage({
  1. required String imageUrl,
  2. BoxFit fit = BoxFit.cover,
  3. double? height,
  4. double? width,
  5. Widget? placeholder,
  6. Widget? errorWidget,
  7. bool circular = false,
})

Builds a native HTML element via HtmlElementView. This bypasses CanvasKit's CORS requirement for cross-origin images.

The load outcome is probed in Dart so placeholder and errorWidget are actually rendered: the platform view alone can only hide a broken , which left an empty hole where the fallback should be.

Implementation

Widget buildWebNativeImage({
  required String imageUrl,
  BoxFit fit = BoxFit.cover,
  double? height,
  double? width,
  Widget? placeholder,
  Widget? errorWidget,
  bool circular = false,
}) {
  if (imageUrl.isEmpty || imageUrl == 'null') {
    return errorWidget ?? const SizedBox.shrink();
  }

  return _WebNativeImage(
    imageUrl: imageUrl,
    fit: fit,
    height: height,
    width: width,
    placeholder: placeholder,
    errorWidget: errorWidget,
    circular: circular,
  );
}