How to get AppBar height in Flutter?

R2T8 picture R2T8 · Apr 28, 2018 · Viewed 55.5k times · Source

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;

Answer

ap14 picture ap14 · Jun 2, 2018

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;