Skip to content

Commit

Permalink
Merge pull request #2854 from dhruvanbhalara/migrate/context_extensions
Browse files Browse the repository at this point in the history
refactor: migrate MediaQuery `context_extensions` to InheritedModel
  • Loading branch information
jonataslaw authored Aug 24, 2023
2 parents 6c2ff16 + e6df6b2 commit 51e1780
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,19 +680,19 @@ context.height
context.heightTransformer()
context.widthTransformer()
/// Similar to MediaQuery.of(context).size
/// Similar to MediaQuery.sizeOf(context);
context.mediaQuerySize()
/// Similar to MediaQuery.of(context).padding
/// Similar to MediaQuery.paddingOf(context);
context.mediaQueryPadding()
/// Similar to MediaQuery.of(context).viewPadding
/// Similar to MediaQuery.viewPaddingOf(context);
context.mediaQueryViewPadding()
/// Similar to MediaQuery.of(context).viewInsets;
/// Similar to MediaQuery.viewInsetsOf(context);
context.mediaQueryViewInsets()
/// Similar to MediaQuery.of(context).orientation;
/// Similar to MediaQuery.orientationOf(context);
context.orientation()
/// Check if device is on landscape mode
Expand All @@ -701,10 +701,10 @@ context.isLandscape()
/// Check if device is on portrait mode
context.isPortrait()
/// Similar to MediaQuery.of(context).devicePixelRatio;
/// Similar to MediaQuery.devicePixelRatioOf(context);
context.devicePixelRatio()
/// Similar to MediaQuery.of(context).textScaleFactor;
/// Similar to MediaQuery.textScaleFactorOf(context);
context.textScaleFactor()
/// Get the shortestSide from screen
Expand Down
28 changes: 14 additions & 14 deletions lib/get_utils/src/extensions/context_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';

extension ContextExt on BuildContext {
/// The same of [MediaQuery.of(context).size]
Size get mediaQuerySize => MediaQuery.of(this).size;
/// The same of [MediaQuery.sizeOf(context)]
Size get mediaQuerySize => MediaQuery.sizeOf(this);

/// The same of [MediaQuery.of(context).size.height]
/// Note: updates when you rezise your screen (like on a browser or
Expand Down Expand Up @@ -65,32 +65,32 @@ extension ContextExt on BuildContext {
/// similar to [MediaQuery.of(context).padding]
TextTheme get textTheme => Theme.of(this).textTheme;

/// similar to [MediaQuery.of(context).padding]
EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding;
/// similar to [MediaQuery.paddingOf(context)]
EdgeInsets get mediaQueryPadding => MediaQuery.paddingOf(this);

/// similar to [MediaQuery.of(context).padding]
MediaQueryData get mediaQuery => MediaQuery.of(this);

/// similar to [MediaQuery.of(context).viewPadding]
EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding;
/// similar to [MediaQuery.viewPaddingOf(context)]
EdgeInsets get mediaQueryViewPadding => MediaQuery.viewPaddingOf(this);

/// similar to [MediaQuery.of(context).viewInsets]
EdgeInsets get mediaQueryViewInsets => MediaQuery.of(this).viewInsets;
/// similar to [MediaQuery.viewInsetsOf(context)]
EdgeInsets get mediaQueryViewInsets => MediaQuery.viewInsetsOf(this);

/// similar to [MediaQuery.of(context).orientation]
Orientation get orientation => MediaQuery.of(this).orientation;
/// similar to [MediaQuery.orientationOf(context)]
Orientation get orientation => MediaQuery.orientationOf(this);

/// check if device is on landscape mode
bool get isLandscape => orientation == Orientation.landscape;

/// check if device is on portrait mode
bool get isPortrait => orientation == Orientation.portrait;

/// similar to [MediaQuery.of(this).devicePixelRatio]
double get devicePixelRatio => MediaQuery.of(this).devicePixelRatio;
/// similar to [MediaQuery.devicePixelRatioOf(context)]
double get devicePixelRatio => MediaQuery.devicePixelRatioOf(this);

/// similar to [MediaQuery.of(this).textScaleFactor]
double get textScaleFactor => MediaQuery.of(this).textScaleFactor;
/// similar to [MediaQuery.textScaleFactorOf(context)]
double get textScaleFactor => MediaQuery.textScaleFactorOf(this);

/// get the shortestSide from screen
double get mediaQueryShortestSide => mediaQuerySize.shortestSide;
Expand Down

0 comments on commit 51e1780

Please sign in to comment.