widget_ext.dart
3.17 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
import 'package:flutter/material.dart';
extension WidgetExt on Widget {
Expanded expanded({int flex = 1}) {
return Expanded(flex: flex, child: this);
}
SafeArea safe() {
return SafeArea(child: this);
}
ClipRRect round({double? radius, BorderRadius? borderRadius}) {
return ClipRRect(
borderRadius: borderRadius ?? BorderRadius.all(Radius.circular(radius ?? 5)),
child: this,
);
}
Container height(double height, {Alignment? alignment}) {
return Container(height: height, alignment: alignment, child: this);
}
Container height48({Alignment? alignment}) {
return Container(height: 48, alignment: alignment, child: this);
}
Container paddingALL(double padding) {
return Container(child: this, padding: EdgeInsets.all(padding));
}
Container paddingTopBottom(double padding) {
return Container(child: this, padding: EdgeInsets.only(bottom: padding, top: padding));
}
Container paddingBottom(double padding) {
return Container(child: this, padding: EdgeInsets.only(bottom: padding));
}
Container paddingTop(double padding) {
return Container(child: this, padding: EdgeInsets.only(top: padding));
}
Widget paddingLeftRight(double padding) {
return Container(child: this, padding: EdgeInsets.only(left: padding, right: padding));
}
Container paddingLeft(double padding) {
return Container(child: this, padding: EdgeInsets.only(left: padding));
}
Container paddingRight(double padding) {
return Container(child: this, padding: EdgeInsets.only(right: padding));
}
Row rowRight() {
return Row(mainAxisAlignment: MainAxisAlignment.end, children: [this]);
}
Row rowLeft() {
return Row(mainAxisAlignment: MainAxisAlignment.start, children: [this]);
}
Row rowCenter() {
return Row(mainAxisAlignment: MainAxisAlignment.center, children: [this]);
}
Widget click(
GestureTapCallback? onTap, {
Color? color,
double? radius,
BorderRadius? borderRadius,
Color? bgColor,
}) {
if (color != null) {
var border = radius == null ? null : BorderRadius.all(Radius.circular(radius));
return getMaterialInkWell(
this,
onTap,
color,
borderRadius: borderRadius ?? border,
bgColor: bgColor,
);
}
return getWhiteInkWell(this, onTap);
}
///当InkWell效果失效时,使用这个套件
Widget getMaterialInkWell(
Widget widget,
GestureTapCallback? onTap,
Color? color, {
BorderRadius? borderRadius,
Color? splashColor,
Color? bgColor = Colors.white,
}) {
return Material(
color: bgColor,
child: Ink(
decoration: BoxDecoration(
color: color,
borderRadius: borderRadius,
),
child: InkWell(
onTap: onTap,
splashColor: splashColor,
borderRadius: borderRadius,
child: widget,
),
),
);
}
///当InkWell效果失效时,使用这个套件
Widget getWhiteInkWell(Widget widget, GestureTapCallback? onTap, {BorderRadius? borderRadius}) {
return Material(
child: Ink(
color: Colors.white,
child: InkWell(onTap: onTap, child: widget),
),
);
}
}