size_extension.dart
4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import 'dart:math';
import 'package:flutter/material.dart';
import 'screen_util.dart';
extension SizeExtension on num {
///[ScreenUtil.setWidth]
double get w => ScreenUtil().setWidth(this);
///[ScreenUtil.setHeight]
double get h => ScreenUtil().setHeight(this);
///[ScreenUtil.radius]
double get r => ScreenUtil().radius(this);
///[ScreenUtil.diagonal]
double get dg => ScreenUtil().diagonal(this);
///[ScreenUtil.diameter]
double get dm => ScreenUtil().diameter(this);
///[ScreenUtil.setSp]
double get sp => ScreenUtil().setSp(this);
///smart size : it check your value - if it is bigger than your value it will set your value
///for example, you have set 16.sm() , if for your screen 16.sp() is bigger than 16 , then it will set 16 not 16.sp()
///I think that it is good for save size balance on big sizes of screen
double get spMin => min(toDouble(), sp);
@Deprecated('use spMin instead')
double get sm => min(toDouble(), sp);
double get spMax => max(toDouble(), sp);
///屏幕宽度的倍数
///Multiple of screen width
double get sw => ScreenUtil().screenWidth * this;
///屏幕高度的倍数
///Multiple of screen height
double get sh => ScreenUtil().screenHeight * this;
///[ScreenUtil.setHeight]
SizedBox get verticalSpace => ScreenUtil().setVerticalSpacing(this);
///[ScreenUtil.setVerticalSpacingFromWidth]
SizedBox get verticalSpaceFromWidth =>
ScreenUtil().setVerticalSpacingFromWidth(this);
///[ScreenUtil.setWidth]
SizedBox get horizontalSpace => ScreenUtil().setHorizontalSpacing(this);
///[ScreenUtil.radius]
SizedBox get horizontalSpaceRadius =>
ScreenUtil().setHorizontalSpacingRadius(this);
///[ScreenUtil.radius]
SizedBox get verticalSpacingRadius =>
ScreenUtil().setVerticalSpacingRadius(this);
///[ScreenUtil.diameter]
SizedBox get horizontalSpaceDiameter =>
ScreenUtil().setHorizontalSpacingDiameter(this);
///[ScreenUtil.diameter]
SizedBox get verticalSpacingDiameter =>
ScreenUtil().setVerticalSpacingDiameter(this);
///[ScreenUtil.diagonal]
SizedBox get horizontalSpaceDiagonal =>
ScreenUtil().setHorizontalSpacingDiagonal(this);
///[ScreenUtil.diagonal]
SizedBox get verticalSpacingDiagonal =>
ScreenUtil().setVerticalSpacingDiagonal(this);
}
extension EdgeInsetsExtension on EdgeInsets {
/// Creates adapt insets using r [SizeExtension].
EdgeInsets get r => copyWith(
top: top.r,
bottom: bottom.r,
right: right.r,
left: left.r,
);
EdgeInsets get dm => copyWith(
top: top.dm,
bottom: bottom.dm,
right: right.dm,
left: left.dm,
);
EdgeInsets get dg => copyWith(
top: top.dg,
bottom: bottom.dg,
right: right.dg,
left: left.dg,
);
EdgeInsets get w => copyWith(
top: top.w,
bottom: bottom.w,
right: right.w,
left: left.w,
);
EdgeInsets get h => copyWith(
top: top.h,
bottom: bottom.h,
right: right.h,
left: left.h,
);
}
extension BorderRadiusExtension on BorderRadius {
/// Creates adapt BorderRadius using r [SizeExtension].
BorderRadius get r => copyWith(
bottomLeft: bottomLeft.r,
bottomRight: bottomRight.r,
topLeft: topLeft.r,
topRight: topRight.r,
);
BorderRadius get w => copyWith(
bottomLeft: bottomLeft.w,
bottomRight: bottomRight.w,
topLeft: topLeft.w,
topRight: topRight.w,
);
BorderRadius get h => copyWith(
bottomLeft: bottomLeft.h,
bottomRight: bottomRight.h,
topLeft: topLeft.h,
topRight: topRight.h,
);
}
extension RadiusExtension on Radius {
/// Creates adapt Radius using r [SizeExtension].
Radius get r => Radius.elliptical(x.r, y.r);
Radius get dm => Radius.elliptical(x.dm, y.dm);
Radius get dg => Radius.elliptical(x.dg, y.dg);
Radius get w => Radius.elliptical(x.w, y.w);
Radius get h => Radius.elliptical(x.h, y.h);
}
extension BoxConstraintsExtension on BoxConstraints {
/// Creates adapt BoxConstraints using r [SizeExtension].
BoxConstraints get r => this.copyWith(
maxHeight: maxHeight.r,
maxWidth: maxWidth.r,
minHeight: minHeight.r,
minWidth: minWidth.r,
);
/// Creates adapt BoxConstraints using h-w [SizeExtension].
BoxConstraints get hw => this.copyWith(
maxHeight: maxHeight.h,
maxWidth: maxWidth.w,
minHeight: minHeight.h,
minWidth: minWidth.w,
);
BoxConstraints get w => this.copyWith(
maxHeight: maxHeight.w,
maxWidth: maxWidth.w,
minHeight: minHeight.w,
minWidth: minWidth.w,
);
BoxConstraints get h => this.copyWith(
maxHeight: maxHeight.h,
maxWidth: maxWidth.h,
minHeight: minHeight.h,
minWidth: minWidth.h,
);
}