“uses-material-design: true”不与 pubspec.yaml 中的其他资产一起使用

MML*_*MML 2 yaml dart material-design flutter pubspec

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

\n
uses-material-design: true\n
Run Code Online (Sandbox Code Playgroud)\n

错误

\n
Error detected in pubspec.yaml:\nRestarted application in \xd9\xa8ms.\nError on line 25, column 4: Expected a key while parsing a block mapping.\n   \xe2\x95\xb7\n25 \xe2\x94\x82    assets:\n   \xe2\x94\x82    ^\n   \xe2\x95\xb5\nException: Please correct the pubspec.yaml file at .\\pubspec.yaml\n\n
Run Code Online (Sandbox Code Playgroud)\n

除了这个问题,一切都好pubspec.yaml

\n
name: mi_card\ndescription: A new Flutter application.\n\nversion: 1.0.0+1\n\nenvironment:\n  sdk: ">=2.1.0 <3.0.0"\n\ndependencies:\n  flutter:\n    sdk: flutter\n\n  cupertino_icons: ^0.1.2\n\ndev_dependencies:\n  flutter_test:\n    sdk: flutter\n\n\nflutter:\n\n  # The following line ensures that the Material Icons font is\n  # included with your application, so that you can use the icons in\n  # the material Icons class.\n  uses-material-design: true\n\n  # To add assets to your application, add an assets section, like this:\n   assets:\n    - images/\n\n   fonts:\n     - family: Pacifico\n       fonts:\n         - asset: fonts/Pacifico-Regular.ttf\n\n     - family: Source Sans Pro\n       fonts:\n        - asset: fonts/SourceSansPro-Regular.ttf\n\n
Run Code Online (Sandbox Code Playgroud)\n

但是因为我需要使用材质图标,所以我需要将其与我的资源一起添加,那么如何解决这个问题?

\n

Moa*_*zhy 6

pubspec.yaml对缩进敏感。

并且您的文件后 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
Run Code Online (Sandbox Code Playgroud)