没有 AppBar 和 BottomNavigationBar 的 Flutter 屏幕尺寸

Eli*_*lle 5 flutter flutter-layout

我试图在不考虑 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,
          ),
        ),
      ],
    ),
  );
Run Code Online (Sandbox Code Playgroud)

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

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

在此输入图像描述

在此输入图像描述

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

感谢您阅读我的文章并提供帮助!

Bab*_*bul 1

获取宽度很容易,但高度可能很棘手,请按照步骤操作,它将对您有所帮助。

   double heightWithoutappBarNavBar = MediaQuery.of(context).size.height - (kBottomNavigationBarHeight + kToolbarHeight);
Run Code Online (Sandbox Code Playgroud)