DEV Community

Pere Sola
Pere Sola

Posted on

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)