Display images from assets folder in Flutter

Pere Sola - May 21 '23 - - Dev Community
  • 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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .