[英]How can i add native Splash Screen in Flutter app without using packages
它可能不是最好的选择,但如果你想让它在所有版本和所有设备上工作,你可以在 flutter 中制作你自己的闪屏页面。它可以解决你的问题。
例如在您的 main.dart 文件中
runApp(MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.light().copyWith(
primary: Colors.red,
),
),
home: SplashPage(), // here is your splash screen page
));
在您的 SplashPage 文件中,您可以根据需要运行一些异步函数,然后您可以导航到主页。
首先,要添加不带包的原生启动画面,您需要准备以下尺寸的应用程序图标或图像
1- mdpi = 1x pixel
2-xhdpi = 2x pixel
3-xxhdpi = 3x pixels
4- xxxhdpi = 4x pixel
5-hdpi = 1.5x pixels
as x is the size of the ixcons
然后在路径中添加所有与每个应用程序图标同名的图标,就像这个图像一样
在android/app/src/main/res/drawable/launch_background.xml写入如下代码
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/color_name" />
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/image or app icon name" />
</item>
然后改变颜色
1-create colors file at
example_app/android/app/src/main/res/values/
2- write the color code you want
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_color">#ED9728</color>
</resources>
使用flutter_native_splash: ^2.2.17 package 生成不同平台的原生启动画面
您可以在dev_dependencies
。 这将使它可用作生成启动画面的命令行工具,但 package 不会编译到您的应用程序中。 如果您甚至不想将它保留在您的dev_dependencies
中,您可以运行它一次,将它从您的项目中删除,然后如果您想进行额外的手动调整,则检查哪些文件是有机会的。
完全披露:我维护这个 package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.