Flutter,pubspec.yaml 文件显示一些错误
Posted
技术标签:
【中文标题】Flutter,pubspec.yaml 文件显示一些错误【英文标题】:Flutter,pubspec.yaml file is showing some errors 【发布时间】:2020-08-24 22:53:16 【问题描述】:我不知道发生了什么,但我无法使用 pubspec.yaml
file.Pub get 不加载依赖项通过资产图像插入图像。
请帮帮我。我正在运行一个颤振项目。
这是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 结束
【问题讨论】:
【参考方案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 中检测到错误:预期“资产”是一个列表,但得到了 -images/khushi.jpg(字符串)。请更正 C:\Users\khush\AndroidStudioProjects\mi_card_flutter\pubspec.yaml 中的 pubspec.yaml 文件 进程以退出代码 1 完成,现在正在显示...基本上 pub get 不起作用 预期“资产”是一个列表,但得到了 -assests/images/(字符串)。这是什么意思? 预期的“资产”是一个列表,但得到了 -assests/images/(字符串)。 贴一张你的图片所在目录的截图@KhushiZawar 我也添加了截图【参考方案2】:请在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
【讨论】:
C:\Users\khush\Downloads\flutter_windows_v1.12.13+hotfix.9-stable\flutter\bin\flutter.bat --no-color pub get 在 pubspec.yaml 中检测到错误:预期“ assets" 是一个列表,但得到了 images/khushi.jpg (String)。请更正 C:\Users\khush\AndroidStudioProjects\trial\pubspec.yaml 中的 pubspec.yaml 文件 再次相同! @KhushiZawar 请在你使用这张图片的地方添加你的类文件代码? 好的,错误得到解决,现在显示这个,pub get 没有加载 C:\Users\khush\Downloads\flutter_windows_v1.12.13+hotfix.9-stable\flutter\bin\flutter.bat --no-color pub get 在 mi_card_flutter 中运行“flutter pub get”... 1.1s 进程以退出代码 0 结束 主要 dart 代码:import 'package:flutter/cupertino.dart'import 'package:flutter/material.dart'; void main() runApp(Myapp()); class Myapp extends StatelessWidget @override Widget build(BuildContext context) return MaterialApp( home: Scaffold( backgroundColor: Colors.black, body: SafeArea( child: Column( children:所以终于在这个疑问上花了 3 个小时后。我得到了答案。我所做的是从终端运行 pub get 并且它起作用了!
【讨论】:
以上是关于Flutter,pubspec.yaml 文件显示一些错误的主要内容,如果未能解决你的问题,请参考以下文章
Flutter工程代码管理 pubspec.yaml.packages 与 pubspec.lock文件的来龙去脉
Flutter工程代码管理 pubspec.yaml.packages 与 pubspec.lock文件的来龙去脉
Flutter pubspec.yaml,音频播放器无法正常工作