【问题标题】:Flutter screen size without AppBar and BottomNavigationBar没有 AppBar 和 BottomNavigationBar 的 Flutter 屏幕尺寸
【发布时间】:2022-01-17 05:28:37
【问题描述】:

我试图在不考虑 AppBar 和 BottomNavigationBar 的情况下获得屏幕的确切尺寸

代码如下:

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,
          ),
        ),
      ],
    ),
  );

通过这样做,我得到的高度比没有 AppBar 和 BottomNavigationBar 的实际屏幕尺寸略大

在下面的屏幕截图中,您可以看到我如何滚动一点

如何计算该屏幕区域的准确高度?

感谢您阅读并提供帮助!

【问题讨论】:

标签: flutter flutter-layout


【解决方案1】:

获得 width 很容易,但 height 可能很棘手,请按照对您有帮助的步骤..

   double heightWithoutappBarNavBar = MediaQuery.of(context).size.height - (kBottomNavigationBarHeight + kToolbarHeight);

【讨论】:

  • 嗨,Babul,感谢您的帖子,但不幸的是它没有帮助检查填充属性后,它们的值都为 0,因此布局没有变化
  • 使用下面的代码。让我知道它是否有效... double heightWithoutappBarNavbar = MediaQuery.of(context).size.height - (kBottomNavigationBarHeight + kToolbarHeight);
  • 嗨,Babul,这和我已经做过的一样,只是结构不同,它不起作用:(
【解决方案2】:

应该这样做。

MediaQuery.of(context).size.height - (MediaQuery.of(context).padding.top + kToolbarHeight + kBottomNavigationBarHeight) 

我认为您必须删除默认的顶部填充

【讨论】:

    猜你喜欢
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多