Skip to content

Reduced unnecessary rebuilds by using MediaQuery as InheritedModel #54

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Container(
What if you ONLY want to update the padding based on the device screen size. You could do.

```dart
var deviceType = getDeviceType(MediaQuery.of(context).size);
var deviceType = getDeviceType(MediaQuery.sizeOf(context));
var paddingValue = 0;
switch(deviceType) {
case DeviceScreenType.desktop:
Expand Down
2 changes: 1 addition & 1 deletion example/lib/views/home/home_view_tablet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HomeViewTablet extends StatelessWidget {
),
AppDrawer()
];
var orientation = MediaQuery.of(context).orientation;
var orientation = MediaQuery.orientationOf(context);
return Scaffold(
body: orientation == Orientation.portrait
? Column(children: children)
Expand Down
2 changes: 1 addition & 1 deletion example/lib/widgets/app_drawer/app_drawer_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppDrawerMobile extends StatelessWidget {

@override
Widget build(BuildContext context) {
var orientation = MediaQuery.of(context).orientation;
var orientation = MediaQuery.orientationOf(context);
return Container(
width: orientation == Orientation.portrait ? 250 : 100,
decoration: BoxDecoration(color: Colors.white, boxShadow: [
Expand Down
4 changes: 2 additions & 2 deletions lib/src/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ T getValueForScreenType<T>({
T? desktop,
T? watch,
}) {
var deviceScreenType = getDeviceType(MediaQuery.of(context).size);
var deviceScreenType = getDeviceType(MediaQuery.sizeOf(context));
// If we're at desktop size
if (deviceScreenType == DeviceScreenType.desktop) {
// If we have supplied the desktop layout then display that
Expand Down Expand Up @@ -212,7 +212,7 @@ T getValueForRefinedSize<T>({
T? extraLarge,
T? small,
}) {
var refinedSize = getRefinedSize(MediaQuery.of(context).size);
var refinedSize = getRefinedSize(MediaQuery.sizeOf(context));
// If we're at extra large size
if (refinedSize == RefinedSize.extraLarge) {
// If we have supplied the extra large layout then display that
Expand Down
10 changes: 5 additions & 5 deletions lib/src/widget_builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class ResponsiveBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, boxConstraints) {
var mediaQuery = MediaQuery.of(context);
var size = MediaQuery.sizeOf(context);
var sizingInformation = SizingInformation(
deviceScreenType: getDeviceType(mediaQuery.size, breakpoints),
deviceScreenType: getDeviceType(size, breakpoints),
refinedSize: getRefinedSize(
mediaQuery.size,
size,
refinedBreakpoint: refinedBreakpoints,
),
screenSize: mediaQuery.size,
screenSize: size,
localWidgetSize:
Size(boxConstraints.maxWidth, boxConstraints.maxHeight),
);
Expand Down Expand Up @@ -65,7 +65,7 @@ class OrientationLayoutBuilder extends StatelessWidget {
Widget build(BuildContext context) {
return Builder(
builder: (context) {
var orientation = MediaQuery.of(context).orientation;
var orientation = MediaQuery.orientationOf(context);
if (mode != OrientationLayoutBuilderMode.portrait &&
(orientation == Orientation.landscape ||
mode == OrientationLayoutBuilderMode.landscape)) {
Expand Down