Flutter 挖孔屏的状态栏占用问题怎么解决,横屏后去掉了状态栏,还是会有一块黑色的竖条

使用下方代码后依旧有一条黑色的区域

Dart 复制代码
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    ///关闭状态栏,与底部虚拟操作按钮
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);//隐藏状态栏,底部按钮栏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    ///显示状态栏,与底部虚拟操作按钮
    SystemChrome.setEnabledSystemUIOverlays(
        [SystemUiOverlay.top, SystemUiOverlay.bottom]);
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
  }

在这种情况下是因为相机,你可以通过以下方式解决这个问题:

android/app/src/main/res/values/styles.xml

并添加以下行:

Dart 复制代码
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>

这就是我的"styles.xml"现在的样子:

Dart 复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> <!-- This is the added line -->
</style>
</resources>

如果你在"values-nigh"文件夹中有另一个"styles.xml"文件,请确保对它做同样的操作。

相关推荐
傅里叶2 小时前
Flutter项目使用 buf.build
flutter
恋猫de小郭4 小时前
iOS 26 开始强制 UIScene ,你的 Flutter 插件准备好迁移支持了吗?
android·前端·flutter
yuanlaile4 小时前
Flutter开发HarmonyOS鸿蒙App商业项目实战已出炉
flutter·华为·harmonyos
CodeCaptain5 小时前
可直接落地的「Flutter 桥接鸿蒙 WebSocket」端到端实施方案
websocket·flutter·harmonyos
stringwu5 小时前
Flutter 中的 MVVM 架构实现指南
前端·flutter
消失的旧时光-194318 小时前
Flutter 异步体系终章:FutureBuilder 与 StreamBuilder 架构优化指南
flutter·架构
消失的旧时光-194321 小时前
Flutter 异步 + 状态管理融合实践:Riverpod 与 Bloc 双方案解析
flutter
程序员老刘1 天前
Flutter版本选择指南:避坑3.27,3.35基本稳定 | 2025年10月
flutter·客户端
—Qeyser1 天前
Flutter网络请求Dio封装实战
网络·flutter·php·xcode·android-studio