Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter setEnabledSystemUIOverlays hide top statusbar

Tags:

flutter

dart

I encountered a problem when I set the SystemUiOverlay.bottom on my appbarwidget using SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]) and noticed that status bar is hidden but once I pull down upper side of the screen it shows and doesn't disappear again. So I came up with the idea to add a gesture detector for the whole widget app to hide it all the time when you press anywhere on the screen. And I am wondering if this is the best solution and there will not be any issues with the performance or whatever. Any thoughts?

void main() => runApp(PlanetsApp());

class PlanetsApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onTap: () => SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]),
      child: new MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Planets App',
        color: Colors.purple,
        home: HomeScreen(),
      ),
    );
  }
}
like image 838
Mugetsu Avatar asked Jun 21 '18 23:06

Mugetsu


People also ask

How do I make my status bar black flutter?

Step 1: Locate the MaterialApp widget. Step 2: Inside the MaterialApp, add the theme parameter with ThemeData class assigned. Step 3: Inside the ThemeData add the appBarTheme parameter and then assign the AppBarTheme class. Step 4: Inside the AppBarTheme , specify the systemOverlayStyle parameter and set the color.


2 Answers

After switching to Flutter I also noticed this behavior :( I dont want to use GestureDetector, and I am not sure where to place SystemChrome.setEnabledSystemUIOverlays so it hides the bar properly...

Instead, I did this: in the Android styles.xml where the App theme is I've added:

<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

This makes the sys-bar to always disappear when the app gets clicked

like image 101
Vladimir Demirev Avatar answered Nov 06 '22 00:11

Vladimir Demirev


For the issue (https://github.com/flutter/flutter/issues/14432) mentioned in comment, I've found a temporary solution. When you hide status bar or bottom bar, Appbar's height remains same and it takes too much space, especially when you are using landscape mode. To fix this, set "primary" property of Scaffold and Appbar false.

  void main() => runApp(MyApp());

  class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => _MyAppState();
  }

  class _MyAppState extends State<MyApp> {        
    @override
    void initState() {
      SystemChrome.setEnabledSystemUIOverlays([]);
      super.initState();
    }

    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          primary: false,
          appBar: AppBar(
            primary: false,
            backgroundColor: Colors.blue,
          ),
          body: Center(child: Text("It works!")),
        ),
      );
    }
  }

Hope it helps!

like image 34
tavuskusu Avatar answered Nov 05 '22 23:11

tavuskusu