bloomImage function
BloomNode
bloomImage({
- required String src,
- String? alt,
- bool decorative = false,
- int? width,
- int? height,
- String? aspectRatio,
- List<
int> ? widths, - String? sizes,
- ImageUrlBuilder? urlBuilder,
- ImageLoading loading = ImageLoading.lazy,
- ImageDecoding decoding = ImageDecoding.async,
- FetchPriority? fetchPriority,
- bool priority = false,
- String? placeholder,
- String? fallbackSrc,
- ImageFit? fit,
- String? className,
- String? style,
- Map<
String, String> ? attrs, - BloomEventHandler? onClick,
- BloomEventHandler? onLoad,
- BloomEventHandler? onError,
- Ref<
Object> ? ref,
High-performance responsive image descriptor helper for Bloom JS Native.
Composes a standard <img> element with performance and accessibility best practices:
- Responsive sources: Generates
srcsetandsizesautomatically fromwidthsandurlBuilder. - Lazy loading by default: Defaults to ImageLoading.lazy and ImageDecoding.async to avoid wasting network bandwidth and main-thread CPU cycles on offscreen images during initial load.
- LCP Hero Image Optimization: Pass
priority: truefor above-the-fold hero images. This emitsloading="eager",fetchpriority="high", anddecoding="async", preventing the delayed Largest Contentful Paint (LCP) penalty caused by lazy-loading hero content. - Layout stability (CLS): Providing
widthandheight(or CSSaspectRatio) reserves the correct layout box before image bytes arrive over the network, preventing Cumulative Layout Shift (CLS). - Placeholders: Supports solid CSS colors (e.g.
'#14141a') or data URIs / blurhash URLs rendered immediately as background styles in SSR and client DOM. - Accessibility: Explicitly specify
alttext describing the image, or setdecorative: trueto emitalt=""andaria-hidden="true"for presentational visuals.
SSR and Browser Compatibility
Pure Dart descriptor. During SSR (renderToHtml), it renders a sanitized HTML5 <img>
string with attributes and inline placeholder styles. In the browser DOM (mount), it
instantiates an HTMLImageElement, binds event handlers (onLoad, onError, onClick),
and attaches ref.
bloomImage(
src: '/assets/product.jpg',
alt: 'Wireless Noise-Canceling Headphones',
width: 800,
height: 600,
widths: [400, 800, 1200],
sizes: '(max-width: 600px) 100vw, 800px',
placeholder: '#14141a',
fit: ImageFit.cover,
);
See also:
- BloomImage, the underlying element descriptor class.
- bloomPicture, for art direction and modern format negotiation (AVIF/WebP).
- ImageLoading, ImageDecoding, and FetchPriority for resource loading controls.
Implementation
BloomNode bloomImage({
required String src,
String? alt,
bool decorative = false,
int? width,
int? height,
String? aspectRatio,
List<int>? widths,
String? sizes,
ImageUrlBuilder? urlBuilder,
ImageLoading loading = ImageLoading.lazy,
ImageDecoding decoding = ImageDecoding.async,
FetchPriority? fetchPriority,
bool priority = false,
String? placeholder,
String? fallbackSrc,
ImageFit? fit,
String? className,
String? style,
Map<String, String>? attrs,
BloomEventHandler? onClick,
BloomEventHandler? onLoad,
BloomEventHandler? onError,
Ref<Object>? ref,
}) {
return BloomImage(
src: src,
alt: alt,
decorative: decorative,
width: width,
height: height,
aspectRatio: aspectRatio,
widths: widths,
sizes: sizes,
urlBuilder: urlBuilder,
loading: loading,
decoding: decoding,
fetchPriority: fetchPriority,
priority: priority,
placeholder: placeholder,
fallbackSrc: fallbackSrc,
fit: fit,
className: className,
style: style,
attrs: attrs,
onClick: onClick,
onLoad: onLoad,
onError: onError,
ref: ref,
);
}