[英]Flutter screen size without AppBar and BottomNavigationBar
I am trying to get the exact size of the screen without taking into account the AppBar and BottomNavigationBar我试图在不考虑 AppBar 和 BottomNavigationBar 的情况下获取屏幕的确切大小
Here is the code:这是代码:
double screenSize = MediaQuery.of(context).size.height;
double height = screenSize - kToolbarHeight - kBottomNavigationBarHeight;
return SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: height / 2,
child: Container(
color: Colors.red,
),
),
SizedBox(
height: height / 2,
child: Container(
color: Colors.blue,
),
),
],
),
);
By doing this I am getting a height that is slighly bigger than the actual screensize withouth AppBar and BottomNavigationBar通过这样做,我得到的高度比没有 AppBar 和 BottomNavigationBar 的实际屏幕尺寸略大
In the screenshots below you can see how I can scroll a little bit在下面的屏幕截图中,您可以看到我如何滚动一点
How can I calculate the exact height of that screen area?如何计算该屏幕区域的确切高度?
Thanks for reading me and helping!感谢您阅读我并提供帮助!
Getting width is easy but height can be tricky, Please follow steps it will help you..获取宽度很容易,但高度可能很棘手,请按照对您有帮助的步骤进行操作。
double heightWithoutappBarNavBar = MediaQuery.of(context).size.height - (kBottomNavigationBarHeight + kToolbarHeight);
This should do it.应该这样做。
MediaQuery.of(context).size.height - (MediaQuery.of(context).padding.top + kToolbarHeight + kBottomNavigationBarHeight)
I think there is a default top padding you have to remove我认为您必须删除默认的顶部填充
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.