Warm tip: This article is reproduced from serverfault.com, please click

unable to load image asset in Flutter error in pubspec file

发布于 2019-04-05 10:20:15

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.stack.imgur.com/50OOV.png <=folder structure

Questioner
codeXP
Viewed
11
ehhc 2019-04-05 20:16:14

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