user9033319
user9033319

Reputation:

unable to load image asset in Flutter error in pubspec file

i want to import image asset into my flutter project but unable to do so.

this is my pubspec.yaml file i removed all the comments added by flutter



name: first_try
description: A new Flutter project.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
 
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter




  fonts:
    - family: Raleway
      fonts:
        - asset: fonts/Raleway-Black.ttf
        
    - family: Lato
      fonts:
        - asset: fonts/Lato-Regular.ttf #works till here
    -assets:
      -assets/

Error Given:

[first_try] flutter packages get Running "flutter packages get" in first_try... 0.4s Error detected in pubspec.yaml:

/properties/flutter/properties/assets: type: wanted [array] got -assets/

Please correct the pubspec.yaml file at B:\Flutter_Exercise\first_try\pubspec.yaml exit code 1

[1]: https://i.sstatic.net/50OOV.png <=folder structure

Upvotes: 1

Views: 12902

Answers (4)

Maddiee
Maddiee

Reputation: 288

If you're following the Udemy flutter course. Edit the pubspec.yaml file like below:

flutter:
  uses-material-design: true
  assets:
     - assets/images/dice-1.png
     - assets/images/dice-2.png
     - assets/images/dice-3.png
     - assets/images/dice-4.png
     - assets/images/dice-5.png
     - assets/images/dice-6.png

Upvotes: 0

Muhammad Osama Khan
Muhammad Osama Khan

Reputation: 1

image: AssetImage('images/dice1.png')) flutter: uses-material-design: true asset:

  • images/ whats the problem cant load the pic

Upvotes: 0

You should be use only one tab space before "fonts" and plus tab when use "-" all of below.

Upvotes: 0

ehhc
ehhc

Reputation: 647

I think you might have forgotten an whitespace. Try the following:

flutter:
  assets:
    - assets/

notice the whitespace after the -

Furthermore, i think, you've removed the flutter section while removeing the comments. AFAIK, that's important :)

see https://flutter.dev/docs/development/ui/assets-and-images#specifying-assets for more information

Upvotes: 3

Related Questions