Flutter如何在方向横向上设置小部件全屏尺寸?

Jai*_*Jai 5 dart flutter

我在方向横向模式下的全屏视图中遇到问题,问题仅出现在某些设备上,诺基亚、红米和一加在横向模式下屏幕左侧未完全覆盖。附上下面的屏幕截图

在此输入图像描述

左侧那个空间是我的手机壁纸,小部件没有覆盖全屏。那么我该如何解决这个问题呢?

class TestPage extends StatefulWidget {
  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  bool isFullScreen = false;

  /* To Update Screen Resolution Normal */
  void updateResolutionNormal() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
  }

  /* To Update Screen Resolution LandscapeLeft,LandscapeRight */
  void updateResolutionLandscape() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Container(
        child: GestureDetector(
            onTap: () {
              setState(() {
                isFullScreen = !isFullScreen;
                if (isFullScreen) {
                  updateResolutionLandscape();
                } else {
                  updateResolutionNormal();
                }
              });
            },
            child: Center(child: Text("Hai"))),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢。

Chi*_*ebe 0

我有一个可行的解决方案,请尝试:

body: Container(
        /// Try adding a width and height to your container like so. I set the width and height to the full dimensions of the device
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: GestureDetector(
            onTap: () {
              setState(() {
                isFullScreen = !isFullScreen;
                if (isFullScreen) {
                  updateResolutionLandscape();
                } else {
                  updateResolutionNormal();
                }
              });
            },
            child: Center(child: Text("Hai"))),
      ),
Run Code Online (Sandbox Code Playgroud)

希望它有效!