简体   繁体   English

Flutter 没有 AppBar 和 BottomNavigationBar 的屏幕尺寸

[英]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.

相关问题 我想要 flutter 中的 BottomNavigationBar 和 TabBar 而没有 appBar - I want BottomNavigationBar as well as TabBar in flutter without having appBar 导航到另一个屏幕而没有底部导航栏图标颤动,但将底部导航栏保留在另一个屏幕中 - Navigating to another screen without bottomNavigationBar Icons in flutter but keeping the bottomNavigationBar in anotherScreen Flutter:使用底部导航栏为应用栏颜色设置动画 - Flutter: animate appbar color with bottomnavigationbar BottomNavigationBar 页面缺少 AppBar Flutter - Missing AppBar on BottomNavigationBar page Flutter Flutter 没有 AppBar 的 TabBar - Flutter TabBar Without AppBar 没有 AppBar 的 Flutter 布局 - Flutter layout without AppBar 没有应用栏 Flutter 的抽屉 - Drawer without appbar Flutter MaterialPageRoute 转到一个没有应用程序栏的新页面,将其与 bottomNavigationBar 一起使用 - MaterialPageRoute goes to a new page without the appbar using it with bottomNavigationBar 如何在没有 Flutter 中上一个屏幕的应用栏的情况下推送到 Flutter 中的新屏幕? - How to push to a new screen in Flutter without the appbar from the previous screen in Flutter? 如何在 flutter 中实现此 appbar 设计,其中我将 Navigation 插入 appbar 而不是 bottomNavigationBar - How can I achieve this appbar design in flutter in which I insert Navigation inside appbar rather than bottomNavigationBar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM