Showing
10 changed files
with
154 additions
and
93 deletions
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` is larger than 800p. | ||
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 | -} |
1 | -import '../../utils.dart'; | ||
2 | - | ||
3 | -extension GetDynamicUtils on dynamic { | ||
4 | - bool get isNull => GetUtils.isNull(this); | ||
5 | - bool get isNullOrBlank => GetUtils.isNullOrBlank(this); | ||
6 | - bool get isOneAKind => GetUtils.isOneAKind(this); | ||
7 | - bool isLengthLowerThan(int maxLength) => | ||
8 | - GetUtils.isLengthLowerThan(this, maxLength); | ||
9 | - bool isLengthGreaterThan(int maxLength) => | ||
10 | - GetUtils.isLengthGreaterThan(this, maxLength); | ||
11 | - bool isLengthGreaterOrEqual(int maxLength) => | ||
12 | - GetUtils.isLengthGreaterOrEqual(this, maxLength); | ||
13 | - bool isLengthLowerOrEqual(int maxLength) => | ||
14 | - GetUtils.isLengthLowerOrEqual(this, maxLength); | ||
15 | - bool isLengthEqualTo(int maxLength) => | ||
16 | - GetUtils.isLengthEqualTo(this, maxLength); | ||
17 | - bool isLengthBetween(int minLength, int maxLength) => | ||
18 | - GetUtils.isLengthBetween(this, minLength, maxLength); | ||
19 | -} |
1 | +import 'package:flutter/material.dart'; | ||
2 | +import 'package:flutter/widgets.dart'; | ||
3 | +import 'package:flutter/foundation.dart'; | ||
4 | + | ||
5 | +extension ContextExtensionss on BuildContext { | ||
6 | + /// The same of [MediaQuery.of(context).size] | ||
7 | + Size get mediaQuerySize => MediaQuery.of(this).size; | ||
8 | + | ||
9 | + /// The same of [MediaQuery.of(context).size.height] | ||
10 | + /// Note: updates when you rezise your screen (like on a browser or desktop window) | ||
11 | + double get height => mediaQuerySize.height; | ||
12 | + | ||
13 | + /// The same of [MediaQuery.of(context).size.width] | ||
14 | + /// Note: updates when you rezise your screen (like on a browser or desktop window) | ||
15 | + double get width => mediaQuerySize.width; | ||
16 | + | ||
17 | + /// Gives you the power to get a portion of the height. | ||
18 | + /// Useful for responsive applications. | ||
19 | + /// | ||
20 | + /// [dividedBy] is for when you want to have a portion of the value you would get | ||
21 | + /// like for example: if you want a value that represents a third of the screen | ||
22 | + /// you can set it to 3, and you will get a third of the height | ||
23 | + /// | ||
24 | + /// [reducedBy] is a percentage value of how much of the height you want | ||
25 | + /// if you for example want 46% of the height, then you reduce it by 56%. | ||
26 | + double heightTransformer({double dividedBy = 1, double reducedBy = 0.0}) { | ||
27 | + return (mediaQuerySize.height - | ||
28 | + ((mediaQuerySize.height / 100) * reducedBy)) / | ||
29 | + dividedBy; | ||
30 | + } | ||
31 | + | ||
32 | + /// Gives you the power to get a portion of the width. | ||
33 | + /// Useful for responsive applications. | ||
34 | + /// | ||
35 | + /// [dividedBy] is for when you want to have a portion of the value you would get | ||
36 | + /// like for example: if you want a value that represents a third of the screen | ||
37 | + /// you can set it to 3, and you will get a third of the width | ||
38 | + /// | ||
39 | + /// [reducedBy] is a percentage value of how much of the width you want | ||
40 | + /// if you for example want 46% of the width, then you reduce it by 56%. | ||
41 | + double widthTransformer({double dividedBy = 1, double reducedBy = 0.0}) { | ||
42 | + return (mediaQuerySize.width - ((mediaQuerySize.width / 100) * reducedBy)) / | ||
43 | + dividedBy; | ||
44 | + } | ||
45 | + | ||
46 | + /// Divide the height proportionally by the given value | ||
47 | + double ratio({ | ||
48 | + double dividedBy = 1, | ||
49 | + double reducedByW = 0.0, | ||
50 | + double reducedByH = 0.0, | ||
51 | + }) { | ||
52 | + return heightTransformer(dividedBy: dividedBy, reducedBy: reducedByH) / | ||
53 | + widthTransformer(dividedBy: dividedBy, reducedBy: reducedByW); | ||
54 | + } | ||
55 | + | ||
56 | + /// similar to [MediaQuery.of(context).padding] | ||
57 | + ThemeData get theme => Theme.of(this); | ||
58 | + | ||
59 | + /// similar to [MediaQuery.of(context).padding] | ||
60 | + TextTheme get textTheme => Theme.of(this).textTheme; | ||
61 | + | ||
62 | + /// similar to [MediaQuery.of(context).padding] | ||
63 | + EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding; | ||
64 | + | ||
65 | + /// similar to [MediaQuery.of(context).padding] | ||
66 | + MediaQueryData get mediaQuery => MediaQuery.of(this); | ||
67 | + | ||
68 | + /// similar to [MediaQuery.of(context).viewPadding] | ||
69 | + EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding; | ||
70 | + | ||
71 | + /// similar to [MediaQuery.of(context).viewInsets] | ||
72 | + EdgeInsets get mediaQueryViewInsets => MediaQuery.of(this).viewInsets; | ||
73 | + | ||
74 | + /// similar to [MediaQuery.of(context).orientation] | ||
75 | + Orientation get orientation => MediaQuery.of(this).orientation; | ||
76 | + | ||
77 | + /// check if device is on landscape mode | ||
78 | + bool get isLandscape => orientation == Orientation.landscape; | ||
79 | + | ||
80 | + /// check if device is on portrait mode | ||
81 | + bool get isPortrait => orientation == Orientation.portrait; | ||
82 | + | ||
83 | + /// similar to [MediaQuery.of(this).devicePixelRatio] | ||
84 | + double get devicePixelRatio => MediaQuery.of(this).devicePixelRatio; | ||
85 | + | ||
86 | + /// similar to [MediaQuery.of(this).textScaleFactor] | ||
87 | + double get textScaleFactor => MediaQuery.of(this).textScaleFactor; | ||
88 | + | ||
89 | + /// get the shortestSide from screen | ||
90 | + double get mediaQueryShortestSide => mediaQuerySize.shortestSide; | ||
91 | + | ||
92 | + /// True if width be larger than 800 | ||
93 | + bool get showNavbar => (width > 800); | ||
94 | + | ||
95 | + /// True if the shortestSide is smaller than 600p | ||
96 | + bool get isPhone => (mediaQueryShortestSide < 600); | ||
97 | + | ||
98 | + /// True if the shortestSide is largest than 600p | ||
99 | + bool get isSmallTablet => (mediaQueryShortestSide >= 600); | ||
100 | + | ||
101 | + /// True if the shortestSide is largest than 720p | ||
102 | + bool get isLargeTablet => (mediaQueryShortestSide >= 720); | ||
103 | + | ||
104 | + /// True if the current device is Tablet | ||
105 | + bool get isTablet => isSmallTablet || isLargeTablet; | ||
106 | + | ||
107 | + /// Returns a specific value according to the screen size | ||
108 | + /// if the device width is higher than or equal to 1200 return [desktop] value. | ||
109 | + /// if the device width is higher than or equal to 600 and less than 1200 | ||
110 | + /// return [tablet] value. | ||
111 | + /// if the device width is less than 300 return [watch] value. | ||
112 | + /// in other cases return [mobile] value. | ||
113 | + T responsiveValue<T>({ | ||
114 | + T mobile, | ||
115 | + T tablet, | ||
116 | + T desktop, | ||
117 | + T watch, | ||
118 | + }) { | ||
119 | + double deviceWidth = mediaQuerySize.shortestSide; | ||
120 | + | ||
121 | + if (kIsWeb) { | ||
122 | + deviceWidth = mediaQuerySize.width; | ||
123 | + } | ||
124 | + if (deviceWidth >= 1200 && desktop != null) return desktop; | ||
125 | + if (deviceWidth >= 600 && tablet != null) return tablet; | ||
126 | + if (deviceWidth < 300 && watch != null) return watch; | ||
127 | + return mobile; | ||
128 | + } | ||
129 | +} |
1 | +import '../regex/get_utils.dart'; | ||
2 | + | ||
3 | +extension GetDynamicUtils on dynamic { | ||
4 | + /// It's This is overloading the IDE's options. Only the most useful and popular options will stay here. | ||
5 | + | ||
6 | + bool get isNull => GetUtils.isNull(this); | ||
7 | + bool get isNullOrBlank => GetUtils.isNullOrBlank(this); | ||
8 | + | ||
9 | + // bool get isOneAKind => GetUtils.isOneAKind(this); | ||
10 | + // bool isLengthLowerThan(int maxLength) => | ||
11 | + // GetUtils.isLengthLowerThan(this, maxLength); | ||
12 | + // bool isLengthGreaterThan(int maxLength) => | ||
13 | + // GetUtils.isLengthGreaterThan(this, maxLength); | ||
14 | + // bool isLengthGreaterOrEqual(int maxLength) => | ||
15 | + // GetUtils.isLengthGreaterOrEqual(this, maxLength); | ||
16 | + // bool isLengthLowerOrEqual(int maxLength) => | ||
17 | + // GetUtils.isLengthLowerOrEqual(this, maxLength); | ||
18 | + // bool isLengthEqualTo(int maxLength) => | ||
19 | + // GetUtils.isLengthEqualTo(this, maxLength); | ||
20 | + // bool isLengthBetween(int minLength, int maxLength) => | ||
21 | + // GetUtils.isLengthBetween(this, minLength, maxLength); | ||
22 | +} |
1 | -export 'src/utils/context_extensions/extensions.dart'; | 1 | +export 'src/utils/extensions/export.dart'; |
2 | export 'src/utils/queue/get_queue.dart'; | 2 | export 'src/utils/queue/get_queue.dart'; |
3 | export 'src/utils/platform/platform.dart'; | 3 | export 'src/utils/platform/platform.dart'; |
4 | export 'src/utils/regex/get_utils.dart'; | 4 | export 'src/utils/regex/get_utils.dart'; |
5 | -export 'src/utils/regex/get_utils_extensions.dart'; |
-
Please register or login to post a comment