flutter native splash

 In Flutter, you can create a native splash screen by creating a splash screen Android theme and set the windowBackground to your splash screen image. Here is an example of how you can do this:

  1. Create a drawable resource for your splash screen image and place it in the res/drawable folder of your Android project.

  2. In your res/values/styles.xml file, create a new style for your splash screen theme:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/splash_screen</item> </style>
  1. In your AndroidManifest.xml file, set the android:theme attribute of the <activity> element to @style/SplashTheme:
<activity android:name=".MainActivity" android:theme="@style/SplashTheme" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>

This will display the splash screen image as the background for the MainActivity when the app is launched. You can then use a FlutterAppDelegate subclass to switch to the Flutter app's main screen after a short delay.

import io.flutter.app.FlutterActivity class MainActivity: FlutterActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Set up a timer to switch to the Flutter app's main screen after a delay Handler().postDelayed({ startActivity(Intent(this, FlutterMainActivity::class.java)) finish() }, SPLASH_SCREEN_DELAY) } }

Post a Comment

Previous Post Next Post

Subscribe Us


Get tutorials, Flutter news and other exclusive content delivered to your inbox. Join 1000+ growth-oriented Flutter developers subscribed to the newsletter

100% value, 0% spam. Unsubscribe anytime