Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; 
like image 626
R2T8 Avatar asked Apr 28 '18 11:04

R2T8


People also ask

How do you get the Flutter AppBar height?

Firstly declare the AppBar widget that you will use in your Scaffold. Now you can get the height of your appBar using its preferred size: double height = appBar.

What is kToolbarHeight in Flutter?

kToolbarHeight top-level constant Null safetyThe height of the toolbar component of the AppBar.

What is PreferredSizeWidget in Flutter?

A widget with a preferred size. This widget does not impose any constraints on its child, and it doesn't affect the child's layout in any way. It just advertises a preferred size which can be used by the parent. Parents like Scaffold use PreferredSizeWidget to require that their children implement that interface.


2 Answers

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; 
like image 200
ap14 Avatar answered Sep 16 '22 13:09

ap14


you can use this :

var height = AppBar().preferredSize.height; 

this way is very sample and easy

like image 43
Majid Soltani Avatar answered Sep 20 '22 13:09

Majid Soltani