Search code examples
androidiosdartflutterappbar

How to get AppBar height in Flutter


How can I get the height of an AppBar in Flutter?
I am using the MarialApp Widget ('package:flutter/material.dart').

I have the height of my Context and would like to deduct the height of the appbar.

final double height = MediaQuery.of(context).size.height;

Solution

  • This is not an ideal way, I think, but it will work.

    Firstly declare the AppBar widget that you will use in your Scaffold.

    Widget demoPage() {
      AppBar appBar = AppBar(
        title: Text('Demo'),
      );
      return Scaffold(
        appBar: appBar,
        body: /*
        page body
        */,
      );
    }
    

    Now you can get the height of your appBar using its preferredSized:

    double height = appBar.preferredSize.height;
    

    You can use this height to reduce from the screen height.

    final double height = MediaQuery.of(context).size.height;