我正在使用 flutter_native_splash 包。我该如何修复这个错误?
Pubspec.yaml -
cupertino_icons:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_native_splash:
image: assets/splash.png
color: “6a1b9a”
android: true
fill: true
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
错误:
PS C:\Users\project> flutter pub pub run flutter_native_splash: create
Could not find package "flutter_native_splash". Did you forget to add a dependency?
这是一个非常愚蠢的问题。即使我今天也遇到了这种情况。也许我们引用的是与我们执行命令的地方相同的教程。问题出在创建之前的空格,正确的命令是
flutter pub pub run flutter_native_splash:create
从这里
得到了解决方案在 dev_dependencies 中添加依赖项而不是依赖项
dev_dependencies:
flutter_test:
sdk: flutter
flutter_native_splash: ^0.1.9 //Add this here
在 pub.yaml 文件中的 dev_depences: 下添加 pub
dev_dependencies:
flutter_native_splash: ^1.2.1
将文件添加到项目根文件夹,其中 pub.yaml 是: 奔跑吧
flutter_native_splash.yaml
奔跑吧flutter pub run flutter_native_splash:create --path=flutter_native_splash.yaml
正确命令:flutter pub run flutter_native_splash:create
您只需要在 dev_dependency 中添加 flutter_native_splash 即可。
然后在其后定义“flutter_native_splash:”。
参考图片: PUBSPEC.YAML
添加包时检查缩进,.yaml 需要缩进才能将包嵌套在依赖项下
使用flutter pub get之前记得保存文件,然后使用
dart 运行 flutter_native_splash:create
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0
flutter_native_splash: ^2.4.1
dependencies:
flutter:
sdk: flutter
# flutter_native_splash-development.yaml
flutter_native_splash:
android: true
ios: true
web: false
color: "#01387B"
# image: assets/icons/vloo_logo.png
android_12:
# branding: assets/icons/vloo_logo.png
color: "#01387B"
dart run flutter_native_splash:create