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

Flutter,pubspec.yaml file is showing some errors

我不知道发生了什么,但我无法使用 pubspec.yaml 通过资产图像插入图像 file.Pub get 未加载依赖项。

请帮帮我。我是 运行 一个 flutter 项目。

这里是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

错误是:

Error detected in pubspec.yaml: Expected "assets" to be a list, but got images/ (String). Please correct the pubspec.yaml file at C:\Users\khush\AndroidStudioProjects\mi_card_flutter\pubspec.yaml Process finished with exit code 1

你的 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/

希望对您有所帮助。

请在pubspec.yaml文件中写入assets如下图

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

所以最后在这个 doubt.I 上花了 3 个小时后得到了 answer.What 我做的是 运行 从终端获取 pub 并且成功了!