【问题标题】:Flutter sticky immersive does not handle status bar properly颤振粘性沉浸式无法正确处理状态栏
【发布时间】:2021-12-03 09:52:20
【问题描述】:

这发生在我使用 Flutter 2.5.3 的 Android 12 上

使用时

SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);

顶部状态栏是隐藏的,但它所在的空间完全是黑色且无法使用。

这是我正在使用的代码

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Column(
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      );
}

我想知道我是否会遗漏一些东西

【问题讨论】:

  • 添加到这个。我的手机有个打孔,是 Google Pixel 4a。
  • 我刚刚在运行 Android 11 的三星 Galaxy A51 上进行了尝试,但它仍然会发生。它也有一个打孔相机。

标签: android flutter android-12 android-immersive


【解决方案1】:

您必须从设置中授予应用程序使用全屏模式的权限, 只需在设置中搜索全屏

【讨论】:

    【解决方案2】:

    如果有人仍在寻找解决方案,请在 github 中查看此问题:https://github.com/flutter/flutter/issues/46486

    链接响应中提供的解决方案对我有用:https://github.com/flutter/flutter/issues/46486#issuecomment-654796115

    只需将以下行添加到 'android/app/src/main/res/values/styles.xml'

    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      相关资源
      最近更新 更多