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

Flutter 颤振如何在方向图上设置小部件全屏尺寸?,flutter,dart,Flutter,Dart,我在方向横向模式下的全屏视图中遇到问题,问题仅在于屏幕左侧横向模式下的一些设备诺基亚、redmi和one plus没有完全覆盖。下面附上屏幕截图 在左边那个空间是我的手机纸,小部件并没有覆盖整个屏幕。那么我该如何解决这个问题呢 class TestPage extends StatefulWidget { @override _TestPageState createState() => _TestPageState(); } class _TestPageState exte

我在方向横向模式下的全屏视图中遇到问题,问题仅在于屏幕左侧横向模式下的一些设备诺基亚、redmi和one plus没有完全覆盖。下面附上屏幕截图

在左边那个空间是我的手机纸,小部件并没有覆盖整个屏幕。那么我该如何解决这个问题呢

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"))),
      ),
    );
  }
}
class TestPage扩展StatefulWidget{
@凌驾
_TestPageState createState();
}
类_TestPageState扩展了状态{
bool isFullScreen=false;
/*要更新屏幕分辨率,请单击“正常”*/
void updateResolutionNormal(){
SystemChrome.setPreferredOrientations([
设备定向,景观权,
DeviceOrientation.landscapeLeft,
DeviceOrientation.Up,
DeviceOrientation.down,
]);
}
/*要更新屏幕分辨率,请选择LandscapeLeft、LandscapeRight*/
void updateResolution景观(){
SystemChrome.setPreferredOrientations([
设备定向,景观权,
DeviceOrientation.landscapeLeft,
]);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.white,
主体:容器(
儿童:手势检测器(
onTap:(){
设置状态(){
isFullScreen=!isFullScreen;
如果(全屏显示){
更新解决方案景观();
}否则{
updateResolutionNormal();
}
});
},
子对象:中心(子对象:文本(“Hai”)),
),
);
}
}

提前感谢。

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

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"))),
      ),

希望它能起作用

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

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"))),
      ),

希望它能起作用

我只是在我的机器上运行了你的代码,并将其构建到我的Redmi Note 8中,它运行良好。当我点击切换到横向模式时,整个屏幕都被填满了。所以我不知道问题出在哪里。@Chichebe谢谢。我使用诺基亚6.1plus和Redmi Note 7S进行了测试,但整个屏幕都没有显示。。在那之后,我用三星j7 pro进行了测试,它开始工作了。。那么,诺基亚6.1和redmi note 7s中会出现什么问题呢?我不明白。我只是在我的机器上运行了你的代码,并将其内置到我的redmi note 8中,它工作正常。当我点击切换到横向模式时,整个屏幕都被填满了。所以我不知道问题出在哪里。@Chichebe谢谢。我使用诺基亚6.1plus和Redmi Note 7S进行了测试,但整个屏幕都没有显示。。在那之后,我用三星j7 pro进行了测试,它开始工作了。。那么,诺基亚6.1和redmi note 7s中会出现什么问题呢?我不知道。运气不好,在上面的mediaQuery未填充屏幕上仍然尝试过。还尝试了
\u mediaQueryData=MediaQuery.of(上下文);屏幕宽度px=_mediaQueryData.size.width*_mediaQueryData.devicePixelRatio;屏幕高度px=_mediaQueryData.size.height*_mediaQueryData.devicePixelRatio;屏幕宽度=_mediaQueryData.size.width;屏幕高度=_mediaQueryData.size.height运气不佳,仍然尝试使用上述mediaQuery未填充屏幕。还尝试了
\u mediaQueryData=MediaQuery.of(上下文);屏幕宽度px=_mediaQueryData.size.width*_mediaQueryData.devicePixelRatio;屏幕高度px=_mediaQueryData.size.height*_mediaQueryData.devicePixelRatio;屏幕宽度=_mediaQueryData.size.width;屏幕高度=_mediaQueryData.size.height