size_extension.dart
2.66 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
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.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 sm => min(toDouble(), sp);
///屏幕宽度的倍数
///Multiple of screen width
double get sw => ScreenUtil().screenWidth * this;
///屏幕高度的倍数
///Multiple of screen height
double get sh => ScreenUtil().screenHeight * this;
///[ScreenUtil.setHeight]
Widget get verticalSpace => ScreenUtil().setVerticalSpacing(this);
///[ScreenUtil.setVerticalSpacingFromWidth]
Widget get verticalSpaceFromWidth =>
ScreenUtil().setVerticalSpacingFromWidth(this);
///[ScreenUtil.setWidth]
Widget get horizontalSpace => ScreenUtil().setHorizontalSpacing(this);
///[ScreenUtil.radius]
Widget get horizontalSpaceRadius =>
ScreenUtil().setHorizontalSpacingRadius(this);
///[ScreenUtil.radius]
Widget get verticalSpacingRadius =>
ScreenUtil().setVerticalSpacingRadius(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,
);
}
extension BorderRaduisExtension on BorderRadius {
/// Creates adapt BorderRadius using r [SizeExtension].
BorderRadius get r => copyWith(
bottomLeft: bottomLeft.r,
bottomRight: bottomLeft.r,
topLeft: topLeft.r,
topRight: topRight.r,
);
}
extension RaduisExtension on Radius {
/// Creates adapt Radius using r [SizeExtension].
Radius get r => this
..x.r
..y.r;
}
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,
);
}