Flutter原生启动画面图像未出现- Flutter (Dart)



我添加了Flutter Native启动屏幕到我的dependencies。颜色出现没有问题,但图像不出现,我不知道为什么。

Pubspec.yaml:

#flutter native splash
flutter_native_splash: ^2.2.19
flutter_native_splash:
image: assetsRoderLogoo.png
color: "#2A52BE"
android: true
ios: true
web: true
flutter:
assets:
- assets/

图像确实存在,我已经尝试过使用所有可能的图像大小,我现在使用的大小是192x162图像是透明的,但我不认为这有什么关系。路径是正确的(我存储所有照片的文件是assets)。什么好主意吗?

在你的问题中,可以发现问题。

对于flutter_native_splash,您首先使用了错误的炉渣。实际上必须使用转发渣,就像@Shivam Jamaiwar说的那样。

flutter_native_splash:
image: assets/RoderLogoo.png
color: "#2A52BE"

其次,您应该使用特定的图像文件名而不是yaml文件中的目录名。像这样。因为有时没有特定名称的图像无法从资产文件中加载。

flutter:
assets:
- assets/RoderLogoo.png

编辑:添加和修复的步骤

  1. 在根目录中创建一个名为flutter_native_splash.yaml的特定yaml文件,并从文档中复制粘贴代码。
  2. 创建assets文件夹,并将你的图像添加到该目录。
  3. flutter_native_splash.yaml文件中,您需要设置在本机启动屏幕上显示您的图像。但是正如文档"只能使用一个参数,color和background_image不能同时设置。">像这样添加图像设置background_image: "assets/splash_image.jpg"
  4. 运行flutter pub run flutter_native_splash:createflutter pub run flutter_native_splash:create --flutter_native_splash.yaml
  5. 然后再次运行项目。这对你来说很好,没有别的事可做。但是你需要为Android 12和其他平台添加一些设置。

for path add "/";不是这个"">

flutter_native_splash:

形象:"资产/RoderLogoo.png"

颜色:"# 2 a52be"

android:真

ios:真

那么您需要在保存您的yaml文件后运行三个命令

执行以下命令:

  1. 颤振清洁
  2. flutter pub run flutter_native_splash:create

最新更新