简体   繁体   English

如何在不使用包的情况下在 Flutter 应用程序中添加本机启动画面

[英]How can i add native Splash Screen in Flutter app without using packages

i have applications and i need to use splash screen with background color and app icon in center of it.我有应用程序,我需要在其中心使用带有背景颜色和应用程序图标的启动画面。

在此处输入图像描述

THE problem with MIPMAP , if i used image inside drawble directory it will work, but i need mipmap because it has multiple dhp sizes. MIPMAP的问题,如果我在 drawble 目录中使用图像,它会起作用,但我需要mipmap ,因为它有多个dhp大小。

Anyone know solution of this?有人知道这个的解决方案吗?

NOTE: i know that the android 32 has special demonstration, i need solution that word in all version.注意:我知道 android 32 有专门的演示,我需要解决所有版本中的单词。

thank you.谢谢你。

It may not be the best option, but If you want it to work in all versions and all devices, you can make your own splash screen page in flutter. And it can solve your problem.它可能不是最好的选择,但如果你想让它在所有版本和所有设备上工作,你可以在 flutter 中制作你自己的闪屏页面。它可以解决你的问题。

For example in your main.dart file例如在您的 main.dart 文件中

 runApp(MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.light().copyWith(
          primary: Colors.red,
        ),
      ),
      home: SplashPage(), // here is your splash screen page
    ));

And in your SplashPage file, you can run some async functions if you want, and you can navigate to the main page after that.在您的 SplashPage 文件中,您可以根据需要运行一些异步函数,然后您可以导航到主页。

First, to add a native splash screen without packages you need to prepare the app icons or the images you need with the following sizes首先,要添加不带包的原生启动画面,您需要准备以下尺寸的应用程序图标或图像

 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 

then add all the icons with the same name at path as each app icon at its positions like this images然后在路径中添加所有与每个应用程序图标同名的图标,就像这个图像一样你应该把图像放在的地方

the at android/app/src/main/res/drawable/launch_background.xml write the following code在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>

then to change the color然后改变颜色

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>

颜色代码示例

更改初始屏幕颜色和图标示例

Use flutter_native_splash: ^2.2.17 package to generate native splash screen for different platforms使用flutter_native_splash: ^2.2.17 package 生成不同平台的原生启动画面

You can use flutter_native_splash in your dev_dependencies .您可以在dev_dependencies That will make it available as a command line tool to generate the splash screen but the package will not be compiled into your app.这将使它可用作生成启动画面的命令行工具,但 package 不会编译到您的应用程序中。 If you don't even want to keep it in your dev_dependencies you could run it once, remove it from your project, and then examine what files were chanced if you want to make additional manual tweaks.如果您甚至不想将它保留在您的dev_dependencies中,您可以运行它一次,将它从您的项目中删除,然后如果您想进行额外的手动调整,则检查哪些文件是有机会的。

Full disclosure: I maintain this package.完全披露:我维护这个 package。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM