Flutter,pubspec.yaml文件显示一些错误

时间:2020-05-09 10:19:30

标签: xcode flutter dart flutter-dependencies flutter-web

我不知道发生了什么,但是我无法使用pubspec.yaml文件通过Asset image插入图像。Pubget未加载依赖项。

请帮助我。我正在运行一个扑朔迷离的项目。

这是pubspec.yaml文件的代码

name: mi_card_flutter
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    images/khushi.jpg

错误是:

在pubspec.yaml中检测到错误: 期望“资产”是一个列表,但有图像/(字符串)。 请在C:\ Users \ khush \ AndroidStudioProjects \ mi_card_flutter \ pubspec.yaml中更正pubspec.yaml文件 流程结束,退出代码为1

enter image description here

3 个答案:

答案 0 :(得分:0)

您对images/kushi.jpg的缩进是错误的。

尝试以下代码:效果很好:

name: mi_card_flutter
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    -images/

我希望这会有所帮助。

答案 1 :(得分:0)

请如下所示在assets文件的pubspec.yaml中写入

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    images/khushi.jpg

代替此

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    - images/khushi.jpg

答案 2 :(得分:0)

因此,在花了3个小时解决这个疑问之后,终于得到了答案。我所做的就是从终端运行pub get,并且成功了!