找不到包“flutter_native_splash”。您是否忘记添加依赖项?

问题描述 投票:0回答:7

我正在使用 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 yaml
7个回答
4
投票

这是一个非常愚蠢的问题。即使我今天也遇到了这种情况。也许我们引用的是与我们执行命令的地方相同的教程。问题出在创建之前的空格,正确的命令是

flutter pub pub run flutter_native_splash:create

这里

得到了解决方案

1
投票

在 dev_dependencies 中添加依赖项而不是依赖项

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_native_splash: ^0.1.9 //Add this here

1
投票

在 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


1
投票

正确命令:flutter pub run flutter_native_splash:create

您只需要在 dev_dependency 中添加 flutter_native_splash 即可。

然后在其后定义“flutter_native_splash:”。

参考图片: PUBSPEC.YAML


0
投票

添加包时检查缩进,.yaml 需要缩进才能将包嵌套在依赖项下


0
投票

使用flutter pub get之前记得保存文件,然后使用

dart 运行 flutter_native_splash:create


0
投票

更新方法

  1. 确保您的终端位于根目录中(项目的主目录 文件夹)。
  2. 从 pub dev 的 dev 依赖项下添加此包 你的 yaml 文件。 https://pub.dev/packages/flutter_native_splash
  3. 像这样:

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0
  flutter_native_splash: ^2.4.1

  1. 以相同的间距将依赖项下的配置添加到 YAML 文件中:

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"

  1. 运行此命令:

dart run flutter_native_splash:create

  1. 如果您能接受此按摩,就可以开始了。enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.