dart - how can i solve the Image path problem in flutter? - Stack Overflow

admin2025-04-25  2

getting this error again & again but the image path is perfectly alright & dependecy is added properly in the yamal file!

Exception has occurred. FlutterError (Unable to load asset: "assets/images/profile.png". Exception: Asset not found)

assets: - assets/images

this dint soleved the proble

getting this error again & again but the image path is perfectly alright & dependecy is added properly in the yamal file!

Exception has occurred. FlutterError (Unable to load asset: "assets/images/profile.png". Exception: Asset not found)

assets: - assets/images

this dint soleved the proble

Share Improve this question asked Jan 15 at 7:36 Berjil JacobBerjil Jacob 1 4
  • 1 Try to add '/' after images i.e. assets: - assets/images/ – DroidFlutter Commented Jan 15 at 7:59
  • What is your pubspec.yaml? I want to see – Ben the Border Commented Jan 15 at 8:23
  • try checking spelling on both folder names,pubspec.yaml & image.Assets(thisOne) – Md. Yeasin Sheikh Commented Jan 15 at 9:05
  • Please share more information - pubspec.yaml file and the code snippet where you are using the image – MubarakZade Commented Jan 15 at 14:30
Add a comment  | 

2 Answers 2

Reset to default 0

If you want to add all the assets in a folder (say "images" folder), you should add "/" at the end as below in pubspec.yaml.

  assets:
    - assets/images/

Follow the following steps:

  1. Create the folders called assets/images inside project but outside lib folder.
  2. Now Open pubspec.yaml and add:

(The indents must be precise)

  1. After updating pubspec.yaml close the app and RUN IT AGAIN.
  2. Now your code will work:
Container(
  height: 200, //As per your requirement
  width: 200,//As per your requirement
  child: Image(
    image: AssetImage(
      'assets/images/profile.png',
    ),
    fit: BoxFit.cover,
  )
)
转载请注明原文地址:http://anycun.com/QandA/1745595007a90937.html