1

在删除/评论此行之前,我无法将图像、字体等任何资产添加到我的项目应用程序中

uses-material-design: true

错误

Error detected in pubspec.yaml:
Restarted application in ٨ms.
Error on line 25, column 4: Expected a key while parsing a block mapping.
   ╷
25 │    assets:
   │    ^
   ╵
Exception: Please correct the pubspec.yaml file at .\pubspec.yaml

除了这个问题,一切正常pubspec.yaml

name: mi_card
description: A new Flutter application.

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


flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
   assets:
    - images/

   fonts:
     - family: Pacifico
       fonts:
         - asset: fonts/Pacifico-Regular.ttf

     - family: Source Sans Pro
       fonts:
        - asset: fonts/SourceSansPro-Regular.ttf

但是因为我需要使用材质图标,所以我需要将它添加到我的资产中,那么如何解决这个问题呢?

4

1 回答 1

2

pubspec.yaml对缩进很敏感。

并且您的 in 文件 uses-material-design: true缩进一个空格,尝试将其删除,它将起作用。

复制并尝试:

name: mi_card
description: A new Flutter application.

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


flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

    # To add assets to your application, add an assets section, like this:
  assets:
    - images/

  fonts:
    - family: Pacifico
      fonts:
        - asset: fonts/Pacifico-Regular.ttf

    - family: Source Sans Pro
      fonts:
        - asset: fonts/SourceSansPro-Regular.ttf
于 2021-04-16T00:22:17.307 回答