简体   繁体   中英

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

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

您应该在“字体”之前只使用一个制表符空间,并在使用以下所有“-”时加上制表符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM