DEV Community

Pere Sola
Pere Sola

Posted on

4

Display images from assets folder in Flutter

  • Create a folder in the root directory of your app called assets. Inside, place your image i.e. this_is_an_image.png. The relative path will be assets\this_is_an_image.png

  • In pubspec.yaml, under flutter: entry, type the following:

assets:
   - assets/this_is_an_image.png
Enter fullscreen mode Exit fullscreen mode
  • I have been using it like that:
Container(
    decoration: BoxDecoration(
        image: const DecorationImage(
            image: AssetImage('assets\this_is_an_image.png'),
            fit: BoxFit.cover,
            ),
        ),
    ),
);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay