Problem description

When the Flutter application starts on Android, there will be an obvious period of white screen. The duration of the white screen is determined by the device performance. The worse the device performance, the longer the white screen duration.

Problem analysis

In fact, the problem of launching a blank screen is also a common problem in Android native applications. Roughly speaking, the Android system completes the initialization of the application from the moment the user clicks the Launcher Icon to the display of the home page of the application. The process is as follows:

The solution

The solution is simple. The Android native blank screen problem can be solved by setting Windows Background for the Launcher Activity, which is also based on Flutter. The problem of a white screen during Flutter initialization (overwriting a launchView) was optimized to solve the problem in a two-step setup.

  1. In the project of the android/app/SRC/main/res/mipmap – xhdpi/directory to add the splash screen image;
  2. Open the android/app/SRC/main/res/drawable/launch_background. The XML file, the file is the splash screen background, specific how to set up can refer to the android drawable, I in the demo setup is as follows:
<?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/background_dark" />

    <! -- You can insert your own image assets here -->
    <item
        android:bottom="84dp">
        <bitmap
            android:src="@mipmap/launch_image" />
    </item>
</layer-list>
Copy the code

Effect of contrast

Flutter Exercise

Github.com/zh8637688/F…