Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrientationBuilder returns landscape when the keyboard pops up in portrait orientation #21000

Closed
codegrue opened this issue Aug 24, 2018 · 4 comments

Comments

@codegrue
Copy link

@codegrue codegrue commented Aug 24, 2018

When in portrait mode, if a form is on the screen and the keyboard pops up, the OrientationBuilder then thinks it's in landscape mode:

          child: OrientationBuilder(
            builder: (context, orientation) {
              return (orientation == Orientation.portrait)
                  ? // triggers in portrait mode
                  :  // triggers in landscape mode or portrait mode with soft keyboard
            },

I assume it's looking at visible widget dimensions, rather than the actual device orientation.

@zoechi

This comment has been minimized.

Copy link
Contributor

@zoechi zoechi commented Aug 24, 2018

OrientationBuilder rebuilds when the orientation (aspect ratio) of the parent widget changes.
It is not about the orientation of the device. That's a common misconception.
Try to read the docs about OrientationBuilder carefully with this information in mind and you will understand ;-)
To get the orientation of the device, use https://docs.flutter.io/flutter/widgets/MediaQueryData/orientation.html

@codegrue

This comment has been minimized.

Copy link
Author

@codegrue codegrue commented Aug 27, 2018

Thank you for the clarification.

@codegrue codegrue closed this Aug 27, 2018
@billymahmood

This comment has been minimized.

Copy link

@billymahmood billymahmood commented Jul 16, 2019

Hi @codegrue

Did you find a solution to this?

@codegrue

This comment has been minimized.

Copy link
Author

@codegrue codegrue commented Jul 16, 2019

Yes the solution is something like this:

  Widget build(BuildContext context) {
    var orientation = MediaQuery.of(context).orientation;

    return Scaffold(
      body: Form(
        child: (orientation == Orientation.portrait)
            ? _buildPortraitLayout()
            : _buildLandscapeLayout(),
      ),
    );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.