如何在Flutter中获取AppBar的高度? [英] How to get AppBar height in Flutter?
本文介绍了如何在Flutter中获取AppBar的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Flutter中获取 AppBar 的高度?
我正在使用MarialApp窗口小部件('package:flutter/material.dart').
我拥有Context的高度,并想扣除应用栏的高度.
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;
推荐答案
我认为,这不是理想的方法,但是它可以工作.
This is not an ideal way, I think, but it will work.
首先声明要在Scaffold
中使用的AppBar
小部件.
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
*/,
);
}
现在,您可以使用appBar
的
double height = appBar.preferredSize.height;
您可以使用此高度来降低屏幕高度.
You can use this height to reduce from the screen height.
final double height = MediaQuery.of(context).size.height;
这篇关于如何在Flutter中获取AppBar的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文