Flutter sticky immersive does not handle status bar properly
Asked Answered
L

2

3

This happens for me on Android 12 with flutter 2.5.3

When using

SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);

The top status bar is hidden but the space that it was in is completly black and unusable. enter image description here

Here is the code I'm using

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,
            ),
          ],
        ),
      );
}

I'm wondering if I might be missing something

Lorineloriner answered 3/12, 2021 at 9:52 Comment(2)
To add to this. My phone has a punch hole, it's a Google Pixel 4a.Lorineloriner
I just tried this on a Samsung Galaxy A51 running Android 11 and it still happens. It too has a punch hole camera.Lorineloriner
C
9

If someone is still looking for a solution to this, check this issue in github: https://github.com/flutter/flutter/issues/46486

Solution provided in the linked response, worked for me: https://github.com/flutter/flutter/issues/46486#issuecomment-654796115

Simply add the following line to 'android/app/src/main/res/values/styles.xml'

<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
Crystlecs answered 18/2, 2022 at 15:31 Comment(2)
how show status bar when using SystemUiMode.immersiveSticky?Gonad
hi @zeynabfarzaneh any idea how to solve this? thank youOphthalmic
P
0

you have to give permission from settings to your app to use fullscreen mode, just search Full screen in settings

Precinct answered 14/1, 2022 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.