Home > OS >  how can I add assets in flutter pubspec.yaml
how can I add assets in flutter pubspec.yaml

Time:11-04

this is the error that has appeared

I tried to just add (assets/ ) but that didn't solve the problem

CodePudding user response:

The assets to specify in the pubspec should be inside the flutter section.

flutter:
  assets:
    - assets/my_icon.png
    - assets/background.png

also example with directories:

flutter:
  assets:
    - directory/
    - directory/subdirectory/

Take a fast read to the official docs: https://docs.flutter.dev/development/ui/assets-and-images

CodePudding user response:

Follow below steps

  1. Create a new Folder name "assets" parallel to Lib folder

  2. Create a folder name "images" in it.

  3. Define a assets like a below in a "pubspec.yaml"

    assets:

    • assets/images/
  4. Use it like a below

    Image.asset("assets/images/my-profile.png"),

CodePudding user response:

Maybe, try adding ./ before your path to the asset.

Like this ./assets/shoes/

  • Related