Flutter Splash screens for dark and light mode without using packages.


Flutter Splash screens for dark and light mode without using packages.

To support the phone system’s light/dark mode, You have to add this line of code in the Materialapp widget of main.dart file. It changes your App UI not splash Screen theme based on the system light/dark mode. 

main.dart
darkTheme: ThemeData(brightness: Brightness.dark,),

android/app/src/main/res/mipmap-hdpi

Go to your Flutter project, past your image in the
android/app/src/main/res/mipmap-hdpi folder.

If your Flutter application is created using
an older version of the Android then replace these
codes in android/app/src/main/res/drawable
/launch_background.xml
otherwise replace codes in
android/app/src/main/res/drawable-v21
/launch_background.xml

android/app/src/main/res/drawable-v21/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:state_checked="true"
          android:drawable="@color/lightColor" />
   <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/screen_splash" />
    </item>
</layer-list>

Now in android/app/src/main/res/values/ make a file name it colors.xml .

and inside it paste these codes.

android/app/src/main/res/values/colors.xml
<resources>
    <color name="darkColor">#000000</color>
    <color name="lightColor">#ffffff</color>
</resources>

Now in android/app/src/main/res/
create a new folder called drawable-night.
And then inside it create a new file called
launch_background.xml and then paste the following code inside it.

android/app/src/main/res/drawable-night/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:state_checked="true"
          android:drawable="@color/darkColor" />
    <item>
        <bitmap
                android:gravity="center"
                android:src="@mipmap/screen_splash" />
    </item>
</layer-list>

Now we added Splash Screen for Dark and light mode successfully!

Popular posts from this blog

In-App Purchase with null safety in Flutter 2.5.

How to add In-App Purchase subscription in Flutter.

Flutter Native Ad Templates Implementation