Flutter: Create a simple splash screen for Android

The Android system takes some decent amount of time to initialize the app’s processes. In case of an app created with Flutter there is additional initialization work involved for the Flutter engine to start. So the following two events occur before the user can the first screen of the app:

  1. The Android app related processes are initialized.
  2. Flutter specific initialization takes place

The problem: Now if we don’t display anything during this initialization time a blank screen will be displayed to the user which is not at all a good experience for the user. We must try to keep the user engaged.

The opportunity: We can display a SplashScreen with the logo or other content to promote our brand.

The wrong way:  Creating a stateful or stateless widget and displaying it for a few seconds before loading the main widget of the app is a bad idea. The main purpose of a SplashScreen is to keep the user engaged while the system is preparing the app for the user.

The right way:Navigate to the style.xml file inside the android folder of your Flutter project. Create the following two styles if they don’t exists.

Create the two drawables mentioned in the code above @drawable/launch_background ,

and @drawable/normal_background.

Update the AndroidManifest.xml: Set the theme of the main activity to LaunchTheme and add the metadata as shown below.

Now if we run the app we can see a red-colored SplashScreen with the Flutter icon while the app loads.

You can get the companion source code for this tutorial from GitHub
https://github.com/gitanjal/flutter_examples/tree/master/flutter_splash_screen

Leave a Reply

Your email address will not be published. Required fields are marked *