且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Flutter中获取AppBar的高度?

更新时间:2022-12-28 15:52:25

我认为,这不是理想的方法,但是它可以工作.

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;