Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter image adding and emulator running error

I want to add image in android studio. I created a folder named "images" inside the project and pasted the image I wanted to upload there. Then I did the "assets" operation in the "pubspec.yaml" file. I clicked pub get. But I am getting a problem.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

How to include images in your app

1. Create an assets/images folder

  • This should be located in the root of your project, in the same folder as your pubspec.yaml file.
  • In Android Studio you can right click in the Project view
  • You don’t have to call it assets or images. You don’t even need to make images a subfolder. Whatever name you use, though, is what you will register in the pubspec.yaml file.

2. Add your image to the new folder

  • You can just copy your image into assets/images. The relative path of lake.jpg, for example, would be assets/images/lake.jpg.

3. Register the assets folder in pubspec.yaml

  • Open the pubspec.yaml file that is in the root of your project.

  • Add an assets subsection to the flutter section like this:

flutter:
    assets:
      - assets/images/lake.jpg
  • If you have multiple images that you want to include then you can leave off the file name and just use the directory name (include the final /):
flutter:
    assets:
      - assets/images/

4. Use the image in code

  • Get the asset in an Image widget with Image.asset('assets/images/lake.jpg').

5. Restart your app

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading