You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter状态栏消失求助:使用flutter_native_splash等包后状态栏不见

解决Flutter使用flutter_native_splash/flutter_launcher_icons后状态栏消失的问题

我之前也碰到过一模一样的情况,这两个工具包尤其是flutter_native_splash,会自动修改你的原生平台配置文件(Android的styles.xml或iOS的Info.plist),直接改变了状态栏的默认行为——这时候单纯在Flutter层用SystemChrome代码,很容易被原生配置覆盖而不生效。下面是一步步的排查和解决方法:

1. 检查Android端的主题配置

flutter_native_splash会自动修改android/app/src/main/res/values/styles.xml,添加全屏启动页主题,你可以打开这个文件看看是否有类似代码:

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    <!-- 其他启动页配置 -->
</style>

如果主题后缀带Fullscreen,它会强制启动页全屏,甚至影响后续App的状态栏显示。你需要把它改成非全屏主题:

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <!-- 保留其他配置,移除Fullscreen后缀 -->
</style>

同时检查MainActivity对应的主题,确保没有设置全屏相关属性。

2. 检查iOS端的Info.plist配置

对于iOS,flutter_native_splash可能会在ios/Runner/Info.plist中添加全屏相关配置:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

你需要修改这两个配置:

<key>UIStatusBarHidden</key>
<false/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

把状态栏隐藏设为false,并开启基于ViewController的状态栏控制,这样Flutter层的SystemChrome代码才能生效。

3. 调整Flutter代码中SystemChrome的调用时机

你现在是在build方法里调用SystemChrome,但build会被多次执行,且容易被原生配置覆盖。建议把这些代码移到main函数最开头,在runApp之前执行:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // 先初始化状态栏配置
  SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
  SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(statusBarColor: Colors.white));
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  runApp(MyApp());
}

注意必须先调用WidgetsFlutterBinding.ensureInitialized();,否则SystemChrome的配置可能不会被正确应用。

4. 清理缓存并重新构建

修改原生配置后,缓存可能导致修改不生效,执行以下命令重置:

flutter clean
flutter pub get
# 若需要重新生成启动页和图标,再执行下面两行
flutter pub run flutter_native_splash:create
flutter pub run flutter_launcher_icons:main

之后重新运行App,看看状态栏是否恢复正常。

如果以上步骤都试过还是不行,可以把你的flutter_native_splash.yaml和flutter_launcher_icons.yaml配置文件贴出来,我再帮你进一步排查。

内容的提问来源于stack exchange,提问作者Aldy Yuan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:17:27