image asset icon name must be set

475

These are the steps on how to add images in Flutter.

  1. Add your image file to assets folder, you may have to create this folder if it is already not present. Create this folder in your /package root directory

  2. Open pubspec.yaml file and add the following lines there (Keep a note to the spaces)

    assets:        
      - assets/your_image.jpg
    
  3. Run flutter packages get in terminal.

  4. You can now use your image in your code like this

    AssetImage("assets/your_image.jpg")
    
Share:
475
Author by

Ahmed El Sayed

Updated on December 06, 2022

Comments

  • Ahmed El Sayed 19 minutes

    while adding image asset to my flutter app, whatever the name i set the error still the same and refuse to add the image enter image description here

    my flutter doctor output

    /home/ahmed/flutter/bin/flutter --no-color doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v0.5.1, on Linux, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK 27.0.3) [✓] Android Studio (version 3.1) [✓] Connected devices (1 available)

    • No issues found! Process finished with exit code 0

  • F-1 about 4 years
    If you have lots of assets you can just write -assets/ this will tell Flutter that all files within the directory