Flutter v2.5.0 Android Splash Screen

Viewed 23738

I had implemented a native splash screen in my current project and everything was working correctly since I upgraded to v2.5.0 and I am starting to get this deprecation warning on my console:

A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.

I have checked out the given link (which is not that clear btw) and tells me to remove the o.flutter.embedding.android.SplashScreenDrawable API as flutter now automatically displays the splash.

But after running my app without the code no splash screen appears moreover it takes a while to start the app - probably initializing the app without the splash or something.

Am I doing this right or is it an issue with the framework itself?

4 Answers

It is caused by having the following code in your AndroidManifest.xml, which was included by default in previous versions of Flutter:

<meta-data
    android:name="io.flutter.embedding.android.SplashScreenDrawable"
    android:resource="@drawable/launch_background"
/>

The solution is to remove the above code.

Source

Follow this youtube tutorial on how to correctly Create Splash Screen in Flutter App the Right Way in 2021. Ensure to create the launch_background.xml file in both drawable and drawable-v21 folders inside the android/app/src/main/res folder.

Create Splash Screen in Flutter App the Right Way in 2021

If you are using Flutter 2.5, remove the following line in your AndroidManifest.xml file since Flutter 2.5 has no need for it anymore as mentioned here --> android splash migration

<meta-data
 android:name="io.flutter.embedding.android.SplashScreenDrawable"
 android:resource="@drawable/launch_background"/>

Remove the below lines from your AndroidManifest.xml file. In newer versions it's no longer used

<meta-data
     android:name="io.flutter.embedding.android.NormalTheme"
     android:resource="@style/NormalTheme" />
            
<meta-data
      android:name="io.flutter.embedding.android.SplashScreenDrawable"
      android:resource="@drawable/launch_background" />

Here is one solution that worked in my case.

You have a "drawable" and "drawable-v21" folders on the path "android/app/src/main/res/" and you must open the "launch_background.xml" in "drawable-v21" folder, paste and a little bit refactor my code to provide your image or/and color:

<?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/your_color" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/your_image" />
    </item>
</layer-list>

P.S. The image should be in "drawable" folder, not "drawable-v21". You can try, but in my case that didnt work and throw the error.

P.S.2 I didn't change the "AndroidManifest.xml", "styles.xml" and other files.

Related