problems

The default generated Flutter project will display a white screen at startup. The worse the device performance, the longer the white screen will be. Native Android development also suffers from a similar problem, with a white or black screen at startup. In Android development it is common to set up a theme file, which is not expanded here.

How to solve

Flutter already offers a solution. Open the Androidmanifest. XML file of the Flutter project directory “android\app\ SRC \main” and you can see the following contents:

This configuration displays an Android View that displays a startup image before the flutter renders the first frame. Make a good transition between app start loading and start rendering of flutter. All in all, the configuration here is to implement our startup image and eliminate white or black screen. Note here that the version OF Flutter I am currently using is 2.12.0. This is not the case with the earlier version configuration, but the principle is roughly the same.

We already know that from here, go ahead and change @drawable/launch_background.

<? The 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="@android:color/white" /> <! -- You can insert your own image assets here --> <! -- <item> <bitmap android:gravity="center" android:src="@mipmap/launch_image" /> </item> --> </layer-list>Copy the code

Change it to the following:

<? The 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> <bitmap android:gravity="fill" android:src="@mipmap/doubanio" /> </item> </layer-list>Copy the code

Mipmap/Doubanio is a PNG image that you put in the Mipmap directory. So instead of a blank screen, the app starts up with a custom image.

Android: Gravity =”fill” means that the image is set to stretch so that it will fill the entire screen.

Also note that there will be multiple drawable and MIpMA files in the project directory.