Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    Image

    Shows an image — a file from the project or a picture at a network address.

    Type: leaf

    Image src:"data/images/hero.png" fit:cover width:512 height:288
    Image src:"https://example.com/poster.jpg" fit:cover

    Where the image comes from

    The reference itself decides:

    • with a scheme ( https:// , data: ) — an external resource, loaded over the network;
    • anything else — a path from the project root : data/images/hero.png .

    The path is always from the root, not relative to the file where the line is written: a macro may be expanded in another file, and a path from the root points to the same image everywhere.

    A path with .. is an error . It opens from disk in the editor and is rejected on sync, so it breaks exactly after publishing, when it is too late to check.

    Formats

    The app draws png , jpg , webp , gif (including animated ones), bmp , wbmp and svg . Vectors are drawn their own way: as an image they work, but as a background ( #decoration → #image ) or an avatar ( CircleAvatar ) they do not.

    A vector is recolored not with color but with currentColor: — and only where the file itself wrote currentColor : a mark where one part follows the theme and the accent keeps its own color stays two-colored. On the site such a file is embedded into the page as <svg> markup (an external <img> would read its own color, not the page's).

    Image src:"data/images/logo.svg" currentColor:#1f2937 height:16

    The browser can do more: it shows .ico and .avif , but the app does not decode them — on the site the image is there, in the app an empty space remains. The analyzer reports this with the asset_format_unsupported finding.

    Parameters

    Parameter Type Description
    src (or url , or positional 0) string A path from the project root or an address with a scheme
    fit string Fit mode: contain , cover , fill , fitWidth , fitHeight , none , scaleDown
    width double Width
    height double Height
    alignment string Alignment: center (default), topLeft , bottomRight and so on
    color color Tint. Meaningful together with colorBlendMode : on its own it recolors the whole image
    colorBlendMode string How the color is blended: srcIn for a single-color mark, multiply , srcATop , …
    currentColor color Only for svg : the color given to the parts of the file with fill="currentColor" / stroke="currentColor" . The file's other colors do not change. color / colorBlendMode have no effect on a vector
    opacity double 0..1. Dimming without wrapping in Opacity
    repeat string noRepeat (default), repeat , repeatX , repeatY — tiling
    filterQuality string none , low , medium (default), high
    scale double Pixel density of the file : an @2x asset with scale:2 is drawn half the size. Not the on-screen size — that is width / height . A vector does not need it
    #headers object Request headers for an image behind authorization. Only for an address with a scheme
    #centerSlice object Nine-patch: fromLTRB 12 12 20 20 — the middle stretches, the corners stay
    matchTextDirection bool Mirror in RTL
    isAntiAlias bool Anti-aliasing when scaling
    semanticLabel string What the screen reader says and what becomes alt on the site. Without it the image is excluded from semantics rather than announced as empty
    An empty src , a broken link or a missing file gives an empty SizedBox of the given size, with no error on screen. The asset_not_found finding appears in the diagnostics, and in the app the miss goes to the log.

    The given width / height are not only the on-screen size: the image is decoded to that size, not to its original one. Otherwise a 4000×3000 photo in a 48×48 avatar takes tens of megabytes in the cache.

    As a background

    Image draws a picture as an element. To put it as a background UNDER the content use #decoration → #image :

    Container width:320 height:180
      #decoration
        #borderRadius circular 16
        #image "data/images/bg.jpg" fit:cover alignment:topCenter
      Center
        Text "Over the image"

    A vector cannot be a background — for a background use a raster file ( png , jpg , webp ).

    On the site: caption and file weight

    semanticLabel is alt . One word for both renderings: the screen reader in the app says it, on the site it becomes the alt attribute, and image search reads it too. Without it the image on the site gets alt="" — "decoration". Lighthouse accepts that, so the score does not drop, but neither the screen reader nor search learns about the photo.

    Image src:"data/images/office.webp" width:560 height:350 fit:cover
      semanticLabel:"A bright office: a desk by the window"

    What to write:

    • what is shown and why it is on the page — in one sentence, as you would describe it over the phone; without "image of…" or "photo of…" — the screen reader says it is an image itself;
    • for a logo — the company name, not "logo";
    • for an image link — where it leads;
    • next to a caption that already names the image (a portrait above a name) — do not repeat the caption;
    • a pattern, a blurred background, an ornament — no semanticLabel : that is the right answer for decoration.

    #web alt:"…" sets alt only on the site and overrides semanticLabel there — needed only when the site needs different words than the app. A background through #decoration → #image becomes a CSS background-image and has no alt at all: a meaningful photo is an Image .

    The file — about twice the display width, in WebP. The site serves the file as is: there is no srcset and no server-side downscaling, and every extra pixel is downloaded by every visitor, phones included. A photo in a 640 px column — a file of about 1280 px. Before publishing a site, the builds window offers to convert PNG and JPEG files from data/ heavier than 200 KB or longer than 2560 px to WebP — that is a ceiling for oversized files, not fitting to the layout. The weight and size of every image is shown by reeel_assets .

    The first three images of a page load right away, the rest lazily ( loading="lazy" ): the main image of the first screen should come early in the markup and weigh the least of all — PageSpeed measures LCP by it.

    Examples

    Image with a fixed size

    SizedBox width:512 height:288
      ClipRRect
        #borderRadius circular 20
        Image src:"data/images/poster.png" fit:cover width:512 height:288

    Background image in a Stack

    Stack
      Image src:"data/images/bg.jpg" fit:cover
      Positioned bottom:20 left:20
        Text "Title"
          #style fontSize:32 fontWeight:bold color:#FFFFFF

    Nested folders

    Image src:"data/images/onboarding/hero.webp" fit:cover

    A single-color mark in the theme color

    Image src:"data/images/mark.png" width:24 height:24
      color:$theme.primary colorBlendMode:srcIn

    Nine-patch: the middle stretches, the corners stay

    Image src:"data/images/bubble.png" width:200 height:80 fit:fill
      #centerSlice fromLTRB 12 12 20 20

    Image behind authorization

    Image url:"https://cdn.example.com/private.png" width:100 height:100
      #headers Authorization:"Bearer token"

    App only: on the site the image comes through an <img> tag, and it does not send headers.

    Asset with double density

    Image src:"data/images/logo@2x.png" scale:2 semanticLabel:"Logo"

    See also

    • Icon — a Material icon by name
    • ClipRRect — rounding the corners of an image
    • DecoratedBox — a background image through #decoration → #image