Line data Source code
1 : import 'package:flutter/widgets.dart'; 2 : 3 : extension MDQ on BuildContext { 4 0 : Size get mediaQuerySize => MediaQuery.of(this).size; 5 : 6 0 : double get height => mediaQuerySize.height; 7 : 8 0 : double get width => mediaQuerySize.width; 9 : 10 0 : double heightTransformer({double dividedBy = 1, double reducedBy = 0.0}) { 11 0 : return (mediaQuerySize.height - 12 0 : ((mediaQuerySize.height / 100) * reducedBy)) / 13 : dividedBy; 14 : } 15 : 16 0 : double widthTransformer({double dividedBy = 1, double reducedBy = 0.0}) { 17 0 : return (mediaQuerySize.width - ((mediaQuerySize.width / 100) * reducedBy)) / 18 : dividedBy; 19 : } 20 : 21 0 : double ratio( 22 : {double dividedBy = 1, 23 : double reducedByW = 0.0, 24 : double reducedByH = 0.0}) { 25 0 : return heightTransformer(dividedBy: dividedBy, reducedBy: reducedByH) / 26 0 : widthTransformer(dividedBy: dividedBy, reducedBy: reducedByW); 27 : } 28 : 29 : /// similar to MediaQuery.of(this).padding 30 0 : EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding; 31 : 32 : /// similar to MediaQuery.of(this).viewPadding 33 0 : EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding; 34 : 35 : /// similar to MediaQuery.of(this).viewInsets; 36 0 : EdgeInsets get mediaQueryViewInsets => MediaQuery.of(this).viewInsets; 37 : 38 : /// similar to MediaQuery.of(this).orientation; 39 0 : Orientation get orientation => MediaQuery.of(this).orientation; 40 : 41 : /// check if device is on landscape mode 42 0 : bool get isLandscape => orientation == Orientation.landscape; 43 : 44 : /// check if device is on portrait mode 45 0 : bool get isPortrait => orientation == Orientation.portrait; 46 : 47 : /// similar to MediaQuery.of(this).devicePixelRatio; 48 0 : double get devicePixelRatio => MediaQuery.of(this).devicePixelRatio; 49 : 50 : /// similar to MediaQuery.of(this).textScaleFactor; 51 0 : double get textScaleFactor => MediaQuery.of(this).textScaleFactor; 52 : 53 : /// get the shortestSide from screen 54 0 : double get mediaQueryShortestSide => mediaQuerySize.shortestSide; 55 : 56 : /// True if width be larger than 800 57 0 : bool get showNavbar => (width > 800); 58 : 59 : /// True if the shortestSide is smaller than 600p 60 0 : bool get isPhone => (mediaQueryShortestSide < 600); 61 : 62 : /// True if the shortestSide is largest than 600p 63 0 : bool get isSmallTablet => (mediaQueryShortestSide >= 600); 64 : 65 : /// True if the shortestSide is largest than 720p 66 0 : bool get isLargeTablet => (mediaQueryShortestSide >= 720); 67 : 68 : /// True if the current device is Tablet 69 0 : bool get isTablet => isSmallTablet || isLargeTablet; 70 : }