Q: Couldn't get statusbar height - Flutter I tried to get status bar height in flutter using this code MediaQuery.of(context).padding.top but its returning 0.0, I am using Samsung A7. Can someone help me with this?
@override
  Widget build(BuildContext context) {
    final double statusBarHeight = MediaQuery.of(context).padding.top;
    print("statusBarHeight");

    print(statusBarHeight);

    pr = new ProgressDialog(context,
        type: ProgressDialogType.Normal, isDismissible: false);

    //final double bottomnavigationbarheight;
    return SafeArea(
      child: Scaffold(
        body: Container(
            height: MediaQuery.of(context).size.height - statusBarHeight,
            child: PageStorage(
              child: _children[_selectedIndex],
              bucket: bucket,
            )),
        bottomNavigationBar:
            SizedBox(height: 60, child: _bottomNavigationBar(_selectedIndex)),
      ),
    );
  }


A: you need to call this code after building all widgets tree and out of the Widget build method
like this in initState
    double statusBarHeight;  
void initState() { // this WidgetsBinding.instance.addPostFrameCallback method will make sure that all Widgets tree are finished built 
        WidgetsBinding.instance.addPostFrameCallback((_) {
          setState(() => statusBarHeight = MediaQuery.of(context).padding.top);
          print('Status Bar Height $statusBarHeight');
        });  super.initState(); }

