Add image assets

To add an image or assets, make a folder named /assets in the app folder at root location:

/app
/assets
/images
/lib

Now, for each screen create a sub folder as follows:

/app
/assets
/images
/home
/profile
/tabs
/onboarding
/lib

Adding resolution-aware image assets#

Modify your folder structure to this:

/app
/assets
/images
/2.0x
/3.0x
/home
/profile
/tabs
/onboarding
/lib

Next, download all the images in resolutions 1x 2x and 3x. The main asset is assumed to correspond to a resolution of 1.0. On devices with a pixel ratio of 1.8, the asset 2.0x is selected and on devices with a pixel ratio of 2.7, the asset 3.0x is selected.

For example:

/app
/assets
/images
/2.0x
/home
/image_ex.png
/3.0x
/home
/image_ex.png
/home
/image_ex.png
/profile
/tabs
/onboarding
/lib

If the width and height of the rendered image are not specified on the Image widget, the nominal resolution is used to scale the asset so that it occupies the same amount of screen space as the main asset would have, just with a higher resolution.

That is, if .../image_ex.png is 72px by 72px, then .../3.0x/image_ex.png should be 216px by 216px; but they both render into 72px by 72px (in logical pixels), if width and height are not specified.

Now, add these assets to the pubspec.yaml file:

assets:
- assets/images/
- assets/images/home/
- assets/images/2.0x/home/
- assets/images/3.0x/home/
- assets/images/profile/
- assets/images/tabs/
- assets/images/onboarding/

Next, go to the main app and add the image constants in the file /src/config/image_constants.dart:

class AllImages {
AllImages._();
static AllImages _instance = AllImages._();
factory AllImages() => _instance;
String image = 'assets/image/image_ex.png';
}

Set the image asset path in the Image widget as shown below:

Image.asset(
AllImages().image,
fit: BoxFit.contain,
),