Background images in Flutter

Flutter gives you two ways to put an image behind a widget. Here is when to use each, and how to size, overlay and theme the image so it stays sharp and light on memory.

8 min read
Smartphone with a deep blue wave background under floating glass layers on dark slate
In short
  • Use BoxDecoration with a DecorationImage for a plain background, and a Stack with Positioned.fill when you need blur, animation or loading states.
  • Pick BoxFit.cover for full-screen backgrounds and ImageRepeat.repeat only for small seamless tiles.
  • A full-screen image on a 3x phone decodes to about 12 MB. Decode it at screen size with ResizeImage or cacheWidth.
  • Put the background outside the Scaffold, or the keyboard will squash it.
12 MBDecoded size of one full-screen image on a 3x phone
7BoxFit values in Flutter
4.5:1Minimum contrast for body text (WCAG AA)

Flutter has no background-image property. A background is just an image painted behind other widgets, and the framework gives you two ways to do it: a DecorationImage inside a BoxDecoration, or an Image placed at the bottom of a Stack. This guide shows both, then covers what decides whether the result looks sharp and runs smoothly: fit, memory, overlays, the keyboard, dark mode and splash screens.

The checks are the same whether you build the screens in-house or work with a flutter app development company. Every background has a pixel size, a memory cost and a contrast problem, and you can measure all three before release.

If you have read our guide to background images in React Native, much of this will look familiar. The budgets are the same. Only the widgets change.

Should you use DecorationImage or a Stack?

Start with DecorationImage. Move to a Stack when the background needs to do more than sit there.

NeedDecorationImageStack + Image
Static full-screen or card backgroundYes, simplest codeWorks, more code
Tint or overlaycolorFilter or opacitySeparate overlay widget
Seamless tilingrepeat propertyrepeat on Image
Blur, fade-in, parallaxNoYes
Loading and error widgetsonError callback onlyloadingBuilder, errorBuilder
Rounded cornersborderRadius on the same decorationWrap in ClipRRect

Both paint the same pixels. The choice is about how much control you need, not about quality.

How do you set a background with BoxDecoration?

Give a Container a BoxDecoration whose image is a DecorationImage. The child draws on top.

Container(
  decoration: const BoxDecoration(
    image: DecorationImage(
      image: AssetImage('assets/images/bg-linen.jpg'),
      fit: BoxFit.cover,
    ),
  ),
  child: const Center(child: Text('Welcome')),
)

Three details catch people out:

  1. Register the file. List the image, or its folder, under flutter: assets: in pubspec.yaml. A missing entry gives a blank box and an error in the log.
  2. The box needs a size. A Container with a child shrinks to the child. For a full-screen background, wrap the screen body or use SizedBox.expand.
  3. Rounded corners go on the decoration. Add borderRadius to the same BoxDecoration and the image is clipped with it.

The DecorationImage reference lists the rest: alignment, repeat, colorFilter, opacity, scale, filterQuality and onError. alignment matters more than it looks. It decides which part of the image survives a crop.

When is a Stack the better choice?

Use a Stack when the background is a widget in its own right: blurred, animated, faded in, or swapped at runtime. The image goes first, so it paints at the bottom.

Stack(
  children: [
    Positioned.fill(
      child: Image.asset(
        'assets/images/bg-linen.jpg',
        fit: BoxFit.cover,
        excludeFromSemantics: true,
      ),
    ),
    const Positioned.fill(
      child: ColoredBox(color: Color(0x73000000)),
    ),
    const SafeArea(child: HomeContent()),
  ],
)

Positioned.fill stretches the image to the size of the stack. excludeFromSemantics keeps a decorative texture out of the screen reader. The overlay in the middle is black at 45 percent opacity (0x73).

To blur the background itself, wrap the image in ImageFiltered with ImageFilter.blur. Keep BackdropFilter for small frosted panels: it blurs whatever is behind it on every frame, and it costs more on full-screen areas.

Which BoxFit should a background use?

Use BoxFit.cover for nearly every full-screen background. It scales the image evenly until the box is full, then crops the overflow. Flutter has seven values in total:

BoxFitWhat it doesUse it for
coverFills the box, keeps the ratio, crops the restFull-screen and hero backgrounds
containFits the whole image, leaves empty bandsArtwork that must not be cropped
fillStretches width and height separatelyFlat colors and soft gradients only
fitWidthMatches the width, may crop top and bottomHeader bands
fitHeightMatches the height, may crop the sidesTall side panels
noneNatural size, centered, croppedSmall marks on a solid color
scaleDownLike contain, but never scales upLogos and icons, rarely backgrounds

Plan for the portrait crop

Phones are tall. A 4:3 file such as our 1600×1200 backgrounds loses its left and right edges on a portrait screen. Keep the important part near the center, or pick a pattern with no focal point. Calm surfaces like the linen fabric texture or soft gradient mesh backgrounds survive any crop.

Tile only true seamless textures

Set repeat: ImageRepeat.repeat and leave fit empty. The tile is drawn at its own size divided by scale, so a 512-pixel tile with scale: 2.0 repeats every 256 logical pixels. The tile has to be made to repeat, as our guide to seamless tileable textures explains.

How big should the image be?

Decode it at the size of the screen in physical pixels and no larger. The file on disk is not the real cost. A decoded image takes 4 bytes per pixel, whatever the format.

ImagePixelsDecoded in memory
3x phone screen (393×852 logical)1179×2556about 12 MB
Web Backgrounds file1600×1200about 7.7 MB
4000×3000 camera original4000×3000about 48 MB
512×512 seamless tile512×512about 1 MB

Flutter's in-memory image cache holds up to 100 MB by default. A few oversized backgrounds can fill it and push other images out.

Decode at screen size

Image.asset and Image.network take cacheWidth and cacheHeight. For a DecorationImage, wrap the provider in ResizeImage:

final media = MediaQuery.of(context);
final px = (media.size.width * media.devicePixelRatio).round();

DecorationImage(
  image: ResizeImage(const AssetImage('assets/images/bg-linen.jpg'), width: px),
  fit: BoxFit.cover,
)

Set one dimension only, so the ratio is kept.

Ship density variants

Flutter picks bundled variants by folder. Put bg-linen.jpg in assets/images/, a larger copy in assets/images/2.0x/ and a larger one again in assets/images/3.0x/. AssetImage loads the closest match for the device, as described in the Flutter assets guide.

How do you keep text readable on top?

Darken the image under the text. With a DecorationImage this is one line:

colorFilter: ColorFilter.mode(
  Colors.black.withValues(alpha: 0.45),
  BlendMode.srcOver,
),

A black overlay at 40 to 55 percent is a common starting point for white text on a busy texture. The target is the WCAG contrast minimum: 4.5:1 for body text and 3:1 for large text. Measure it on the brightest area that can sit behind text, not on the average. Our article on readable text on background images shows how.

A calmer image needs less overlay. Low-contrast paper, linen and grain textures need far less than photos with sharp edges, so test the actual file instead of copying a fixed value.

Why does the background jump when the keyboard opens?

The background jumps because it sits inside the Scaffold body. Scaffold resizes its body to avoid the keyboard by default, so a cover image is scaled again to the smaller box and visibly jumps.

Move the background outside the Scaffold and make the scaffold transparent:

DecoratedBox(
  decoration: const BoxDecoration(
    image: DecorationImage(
      image: AssetImage('assets/images/bg-linen.jpg'),
      fit: BoxFit.cover,
    ),
  ),
  child: Scaffold(
    backgroundColor: Colors.transparent,
    extendBodyBehindAppBar: true,
    appBar: AppBar(backgroundColor: Colors.transparent, elevation: 0),
    body: const LoginForm(),
  ),
)

The form still moves out of the keyboard's way, but the image stays put. extendBodyBehindAppBar and a transparent AppBar let the image run under the status bar. Setting resizeToAvoidBottomInset: false also stops the jump, but then you must keep the inputs visible yourself.

How do you switch backgrounds for dark mode?

Read the brightness from the theme and pick the file from it:

final dark = Theme.of(context).brightness == Brightness.dark;
final bg = AssetImage(
  dark ? 'assets/images/bg-linen-dark.jpg' : 'assets/images/bg-linen.jpg',
);

The theme follows the system setting when your MaterialApp uses themeMode: ThemeMode.system, and it also respects an in-app override. A dark variant is not the light file with the brightness turned down. Lower the contrast inside the texture, remove pure white highlights and keep the tone close to your dark surface color. Our notes on using backgrounds in dark mode cover the visual side.

Should backgrounds be bundled or loaded from a URL?

Bundle the backgrounds that appear on first launch and on core screens. They work offline and are ready on the first frame.

Load from a URL when backgrounds change often, such as seasonal themes managed from a CMS. Then:

  1. Call precacheImage(provider, context) before the screen opens, so the image is decoded by the time it is needed.
  2. Paint a solid color under the image while it loads. It avoids a white flash.
  3. Serve a file resized for phones. A 4000-pixel original wastes data and memory.
  4. Add a disk cache. Flutter's own cache lives in memory only, so packages such as cached_network_image keep files between launches.

What about splash and onboarding screens?

Keep the splash simple and show the rich background on the first Flutter screen. The native splash appears before the Flutter engine starts, so widgets cannot draw it.

On Android 12 and later, the system splash screen API shows an app icon on a solid color. A full-bleed image is not part of that design. iOS launch screens allow an image, but a splash that differs by platform feels inconsistent. A pattern that works on both:

  1. Splash: icon on a solid color taken from the darkest tone of your background.
  2. First screen: the same color under the image, with the image fading in once precacheImage has finished.
  3. Onboarding: one background per step at most, from the same family of textures.

The shared color hides the hand-off from the native splash to Flutter.

A checklist before you ship

  • Plain backgrounds use DecorationImage, and animated or blurred ones use a Stack.
  • Every image is listed in pubspec.yaml.
  • Full-screen backgrounds use BoxFit.cover, and the key area survives a portrait crop.
  • Images are decoded at screen size with ResizeImage or cacheWidth.
  • Bundled files have 2.0x and 3.0x variants.
  • Text on top reaches 4.5:1 contrast on the brightest part of the image.
  • The background sits outside the Scaffold, so the keyboard does not resize it.
  • Dark mode loads its own file, not a dimmed copy.
  • Remote backgrounds are precached and show a solid color while loading.

Need a starting point? Browse background textures for calm surfaces that work behind text, or the responsive background images guide for the web side of the same problem.

Questions about Flutter backgrounds

How do I set a background image in Flutter?

Give a Container a BoxDecoration with a DecorationImage, set the image to an AssetImage or NetworkImage, and use BoxFit.cover. The container's child is drawn on top of the image.

Why is my Flutter background image not showing?

Most often the asset is missing from pubspec.yaml or the path has a typo. The other common cause is a box with no size: a Container shrinks to its child, so wrap the screen or use SizedBox.expand.

How do I make a background image fill the whole screen?

Put the decorated box outside the Scaffold, make the Scaffold background transparent and use BoxFit.cover. Add extendBodyBehindAppBar with a transparent AppBar so the image also runs under the status bar.

How do I add an overlay to a background image in Flutter?

Use the colorFilter of DecorationImage with a semi-transparent black and BlendMode.srcOver, or place a ColoredBox between the image and the content in a Stack.

What resolution should a Flutter background image be?

Match the largest screen you support in physical pixels, about 1179 by 2556 for a modern 3x phone. Decode it at that size with ResizeImage or cacheWidth to keep memory down.

Keep reading

Built for the web.
Free to download.