我添加了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
编辑:添加和修复的步骤
- 在根目录中创建一个名为
flutter_native_splash.yaml
的特定yaml文件,并从文档中复制粘贴代码。 创建assets文件夹,并将你的图像添加到该目录。 - 在
flutter_native_splash.yaml
文件中,您需要设置在本机启动屏幕上显示您的图像。但是正如文档"只能使用一个参数,color和background_image不能同时设置。">像这样添加图像设置background_image: "assets/splash_image.jpg"
。 - 运行
flutter pub run flutter_native_splash:create
和flutter pub run flutter_native_splash:create --flutter_native_splash.yaml
。 - 然后再次运行项目。这对你来说很好,没有别的事可做。但是你需要为Android 12和其他平台添加一些设置。
for path add "/";不是这个"">
flutter_native_splash:
形象:"资产/RoderLogoo.png"
颜色:"# 2 a52be"
android:真
ios:真
那么您需要在保存您的yaml文件后运行三个命令
执行以下命令:
- 颤振清洁
- flutter pub run flutter_native_splash:create