Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get status bar height in Flutter?

How do I get the status bar height?

enter image description here

like image 835
iDecode Avatar asked Nov 17 '20 10:11

iDecode


People also ask

How do I get the widget height on my flutter?

First, you need to assign a GlobalKey to the widget. If you've assigned the GlobalKey to the widget, you can get the currentContext property of the key and call the findRenderObject() method. The result can be casted to RenderBox . You can get the size from the RenderBox 's size property.

How do I customize my status bar in 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

var height = MediaQuery.of(context).viewPadding.top;

Note: This will only work on mobile devices because other platforms don't have a dedicated status bar and it will returns 0.0 for them.

like image 200
iDecode Avatar answered Oct 27 '22 14:10

iDecode


Hope it will help you, just add latest GetX package in your application and import following library in your code.

import 'package:get/get.dart';

Status Bar Height

To get status bar height use following a bit code:

Get.statusBarHeight;

Bottom Bar Height

To get bottom bar height use following a bit code:

Get.bottomBarHeight;

Screen Height

To get screen height use following a bit code:

Get.height;

Screen Width

To get screen width use following a bit code:

Get.width;

Also you can use SafeArea() widget to ignore overlays to use this just wrap your widget with this.

like image 45
Asad Malik Avatar answered Oct 27 '22 15:10

Asad Malik