FilledStacks / FilledStacks/responsive_builder

use the OrientationBuilder widget rather than MediaQuery.orientation

Open
#39 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Dart
Stars
524
Forks
90
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.