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