To add images from asset folder, follow this simple steps:
- create a folder with name of assets(you can give any name, but assets preferable).
- Register your asset folder and its images in pubspec.yaml.
- Then write this code to show images from assets folder:
Image(
image: AssetImage(
'assets/car.jpg',
),
fit: BoxFit.fitHeight,
),
Do you have a file 'assets/car.jpg' in the root of your project? Thats a file 'car.jpg' under a folder 'assets'
In your pubspec.yaml file (located at the root of your project), you must add reference to that folder. You should be able to find this comment and modify like below:
The indentation is required. The forward slash also indicates its a folder and is required. If you are using VSCode some sort of .yaml formatter may help you get the correct indentation