Home > Enterprise >  How to get height of area top of safe area with Flutter
How to get height of area top of safe area with Flutter

Time:10-01

I have a rounded corner mobile phone. The top part of the phone have the front camera and power icons etc.

I want to get this area height for my Flutter application.

I tried

MediaQuery.of(context).padding.top

But this always return 0

I also tried

MediaQuery.of(context).viewPadding

it also return EdgeInsets.zero

Widget build(BuildContext context) {
    var safePadding = MediaQuery.of(context).viewPadding;
    print("Safe $safePadding");

    return SafeArea(
      child: Scaffold(
        body: _buildVideoContent(),
      ),
    );
  }

Can someone provide some advice to get this height value?

enter image description here

CodePudding user response:

Try using kToolBarHeight property https://api.flutter.dev/flutter/material/AppBar/toolbarHeight.html

CodePudding user response:

if you want to get status bar height, you can write

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

If you want appBar height

double appBarHeight = AppBar().preferredSize.height;
  • Related