Flutter项目使用native splash仍显示默认启动页问题求助
解决Flutter默认启动页在自定义Native Splash前显示的问题
1. 确认flutter_native_splash配置与生成步骤
首先检查pubspec.yaml中的配置是否覆盖必要参数,确保背景色与启动图匹配,避免闪屏:
flutter_native_splash: color: "#ffffff" # 与自定义启动图背景色一致 image: assets/images/splash.png # 你的自定义启动图路径 android: true ios: true android_12: image: assets/images/splash_android12.png color: "#ffffff"
配置完成后必须执行生成命令,确保资源替换生效:
flutter pub run flutter_native_splash:create
2. Android端排查与修复
- 检查
android/app/src/main/res/drawable/launch_background.xml,确保内容为自定义启动图配置,移除默认的@mipmap/ic_launcher引用:<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/white" /> <!-- 与pubspec中color一致 --> <item> <bitmap android:gravity="center" android:src="@drawable/splash" /> <!-- 你的启动图资源 --> </item> </layer-list> - 确认
android/app/src/main/AndroidManifest.xml中启动Activity的android:theme指向@style/LaunchTheme,且styles.xml里的LaunchTheme关联了launch_background:<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> - 清理缓存:执行
flutter clean,删除android/app/build目录后重新编译。
3. iOS端排查与修复
- 打开
ios/Runner/Assets.xcassets,删除默认的LaunchImage,确保flutter_native_splash生成的SplashImage是唯一的启动图资源。 - 检查
ios/Runner/Info.plist,确认UILaunchStoryboardName设置为LaunchScreen,且LaunchScreen.storyboard已被flutter_native_splash修改为使用自定义启动图。 - 清理缓存:执行
flutter clean,删除ios/Pods目录后重新执行pod install,再编译项目。
4. 额外注意事项
- 确保Flutter首屏的背景色与启动图背景色一致,避免视觉上的闪屏错觉。
- 测试时必须冷启动App,热重载无法验证启动页效果。
- Android 12+需单独配置
android_12参数,因为该版本使用Splash Screen API,配置逻辑与低版本不同。
内容的提问来源于stack exchange,提问作者Nithin Pramod
相关产品推荐
相关产品推荐

