如何彻底移除Flutter默认白色启动页?无需自定义启动页
Alright, let's fix that pesky default white splash screen once and for all. If you want zero splash screen (no custom ones either) or to make it as short as physically possible, you need to tweak both Android and iOS native code since Flutter doesn't handle this out of the box. Here's how to do it step by step:
The default white splash comes from native launch drawable and theme settings. Let's strip it entirely:
- Open
android/app/src/main/res/drawable/launch_background.xmland replace its contents with a fully transparent layer list:<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/transparent" /> </layer-list> - Next, open
android/app/src/main/res/values/styles.xmland update theLaunchThemeto enforce transparency and remove any overlay:<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> </style> - For Android 12 and above: Google introduced the SplashScreen API, which might still show a default screen if not disabled. Add this meta-data tag inside the
<application>section ofandroid/app/src/main/AndroidManifest.xml:<meta-data android:name="android.splashscreen.enabled" android:value="false" />
iOS uses a storyboard for the launch screen, so we'll make that fully transparent:
- Open your project in Xcode, navigate to
ios/Runner/LaunchScreen.storyboard. - Select the main
View(the background of the launch screen) in the storyboard editor. In the Attributes Inspector, set the Background color toClear Color. - Double-check your
Info.plistfile (also in theios/Runnerfolder) to ensure there are no leftover launch image configurations. If you previously used launch images instead of the storyboard, delete all those image assets from your project.
Bonus: Minimizing any remaining "flash"
If you still see a tiny split-second flash (from Flutter's initial setup), you can set your Flutter app's initial screen background to match whatever your native app's transparent state transitions to. But with the above steps, you should get as close to "no splash screen" as possible.
内容的提问来源于stack exchange,提问作者Zohaib Hamdule

