PictureSource class

Specification for a single <source> element within a <picture> container.

Used for art direction (serving different aspect ratios or crops based on media queries) and modern image format negotiation (serving AVIF or WebP before legacy JPEG/PNG via type).

When srcset is omitted and widths is provided along with src, toNode automatically generates a responsive srcset attribute string using urlBuilder or defaultImageUrlBuilder.

PictureSource(
  src: '/images/hero.avif',
  type: 'image/avif',
  widths: [640, 1024, 1920],
  sizes: '(max-width: 768px) 100vw, 1200px',
  media: '(min-width: 768px)',
);

See also:

  • bloomPicture, helper creating a <picture> container with sources and fallback image.
  • BloomPicture, the picture element descriptor node.
  • buildSrcSet, the responsive candidate string generator.

Constructors

PictureSource({String? src, String? srcset, List<int>? widths, ImageUrlBuilder? urlBuilder, String? sizes, String? media, String? type, int? width, int? height})
Creates a <source> specification for <picture> elements.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
height int?
Intrinsic height attribute for layout calculation.
final
media String?
Media condition query (e.g. '(min-width: 1024px)' or '(prefers-color-scheme: dark)').
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sizes String?
Responsive sizes query (e.g. '(max-width: 768px) 100vw, 1200px').
final
src String?
Base URL of the source image used for automatic srcset generation.
final
srcset String?
Raw srcset string. If omitted and widths is provided, built automatically via urlBuilder.
final
type String?
MIME type of the source resource (e.g. 'image/avif', 'image/webp').
final
urlBuilder ImageUrlBuilder?
Custom URL builder for generating width variants from src.
final
width int?
Intrinsic width attribute for layout calculation.
final
widths List<int>?
Target widths for automatic srcset generation when src is provided.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toNode() ElNode
Compiles this specification into an ElNode descriptor targeting the void <source> element.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited