Skip to content

Commit

Permalink
MediaQuery as InheritedModel flutter/flutter#114459
Browse files Browse the repository at this point in the history
  • Loading branch information
MominRaza authored Jul 11, 2023
1 parent 62bc9ae commit 0ee7cbd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
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

0 comments on commit 0ee7cbd

Please sign in to comment.