Flutter how to set widget full screen size on orientation landscape?

Viewed 2032

I had an issue in full screen view on orientation landscape mode, the problem is only with some devices nokia, redmi and one plus in landscape mode in left side of screen not covered fully.attaching screen shot below

enter image description here

in left side that space was my mobile walpaper, widget not covering full screen. so how do i solve this ?

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

Thanks in advance.

1 Answers

I have a solution that could work, try:

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

Hope it works!

Related