美文网首页Flutter
采用flutter_native_splash为iOS和andr

采用flutter_native_splash为iOS和andr

作者: 一粒榛子 | 来源:发表于2022-10-14 15:58 被阅读0次

目前用flutter开发app,需要为双平台添加启动图,采用github上的flutter_native_splash.

目前来说说踩下的坑!!!

地址:GitHub - jonbhanson/flutter_native_splash: Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.

先说下集成用法:

 在pubspec.yaml中添加

dependencies:flutter_native_splash:^2.2.11

运行flutter pub get

第一个坑:因为用的flutter版本是3.0,运行flutter pub get后会版本不匹配

解决方法:

1.升级flutter版本,因为flutter_native_splash:^2.2.11需要更高的flutter版本.

2.降低flutter_native_splash:^2.2.11版本为flutter_native_splash:^2.2.7

Customize the following settings and add to your project's pubspec.yaml file or place in a new file in your root project folder named flutter_native_splash.yaml.

第二个坑:自己新建了一个flutter_native_splash.yaml文件,然后设置后运行flutter pub run flutter_native_splash:create,发现不起作用.如果自己创建了文件,应该运行的是flutter pub run flutter_native_splash:create --path=path/to/my/file.yaml命令,其实可以把flutter_native_splash写在自带的yaml文件中.

第三个坑:一开始跑在ios真机上,发现一进去黑屏,已经在Runner工程设置好启动图,最后发现是启动图的问题,启动图是从assets文件里拿的一张图,分辨率很高.找了很久的原因,最后降低分辨率为1080p左右,设置好@2x,@3x图片,发现在ios运行就没问题了

第四个坑:弄完ios开始搞安卓,发现IDEA安装安卓模拟器也是各种坑,因为gradle版本的问题一直无法运行成功.最后终于搞定了.发现一进去白屏,不加载任何图片,使用官方的demo运行也是白屏,最后按照上面截图的配置成功了,其实设置好后在终端运行flutter pub run flutter_native_splash:create会有成功的提示,如果没有,那说明哪里配置有问题

就这样!!!

相关文章

网友评论

    本文标题:采用flutter_native_splash为iOS和andr

    本文链接:https://www.haomeiwen.com/subject/rrlczrtx.html