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

use the OrientationBuilder widget rather than MediaQuery.orientation #39

Open
basnetjiten opened this issue Feb 27, 2022 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@basnetjiten
Copy link

basnetjiten commented Feb 27, 2022

Hello I could see the use of
var orientation = MediaQuery.of(context).orientation;
on OrientationLayoutBuilder
on my use case I could not see the widget build on orientation changes on IPAD simulator. How about we refactor to use the [OrientationBuilder] (https://api.flutter.dev/flutter/widgets/OrientationBuilder-class.html) widget

I guess this would rebuild every time app’s current Orientation changes for current screen.

Here is the the code snippet in my case:

     ScreenTypeLayout(
  breakpoints:
      const ScreenBreakpoints(desktop: 900, tablet: 650, watch: 250),
  mobile: OrientationLayoutBuilder(

      portrait: (context) => const ProgramPortraitView(),
      landscape: (context) => const ProgramLandscapeView()),
  desktop
    : OrientationLayoutBuilder(
      portrait: (context) => const ProgramPortraitView(),
      landscape: (context) => const ProgramLandscapeView()),
)

Suggested OrinetationLayoutBuilder:

@override
Widget build(BuildContext context) {
return OrientationBuilder(
  builder: (context, deviceOrientation) {
    var orientation = deviceOrientation;

    if (mode != OrientationLayoutBuilderMode.portrait &&
        (orientation == Orientation.landscape ||
            mode == OrientationLayoutBuilderMode.landscape)) {
      if (landscape != null) {
        return landscape!(context);
      }
    }

    return portrait(context);
   },
  );
  }
}
@Eimen2018 Eimen2018 added the enhancement New feature or request label Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants