round_button.dart
3.8 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
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:flutter_ex_widget/ex_rich_text2.dart';
import 'package:flutter_ex_widget/ex_text.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
import 'package:flutter_ex_widget/flutter_ex_widget.dart';
class RoundButton extends StatelessWidget {
const RoundButton(
{Key key,
this.width,
this.height = 50,
this.margin = EdgeInsets.zero,
this.radius,
this.bgColor,
this.highlightColor,
this.splashColor,
this.child,
this.text,
this.style,
this.onPressed,
this.image,
this.imgWidth = 13.0,
this.fontSize = 24,
this.gradientStart = MyColours.color_199095,
this.gradientEnd = MyColours.color_199095,
this.textColor = Colors.white,
this.borderColor = Colors.transparent,
this.isBold = true,
this.padding = EdgeInsets.zero,
this.space = 6})
: super(key: key);
final String image;
final double width;
final double height;
final double imgWidth;
final double fontSize;
final Color textColor;
final bool isBold;
/// Empty space to surround the [decoration] and [child].
final EdgeInsetsGeometry margin;
final double radius;
final Color bgColor;
final Color highlightColor;
final Color splashColor;
final Color gradientStart;
final Color gradientEnd;
final Widget child;
final Color borderColor;
final double space;
final String text;
final TextStyle style;
final EdgeInsetsGeometry padding;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
Color _bgColor = bgColor ?? Theme.of(context).primaryColor;
BorderRadius _borderRadius = BorderRadius.circular(radius ?? (height / 2));
return new Container(
padding: padding,
width: width,
height: height,
margin: margin,
decoration: BoxDecoration(
borderRadius: _borderRadius,
border:
Border.all(color: borderColor, width: ScreenUtil().setWidth(2)),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
gradientStart,
gradientEnd,
],
),
),
child: new InkWell(
borderRadius: _borderRadius,
onTap: () => onPressed(),
child: child ??
new Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
!ObjectUtil.isEmptyString(image)
? Padding(
padding: EdgeInsets.only(
left: space, right: space, bottom: 3),
child: Image.asset(
image,
width: ScreenUtil().setWidth(imgWidth),
),
)
: Text(''),
Expanded(
child: Container(
padding: EdgeInsets.only(top: ScreenUtil().setWidth(2)),
child: ExText(
text,
style ??
new TextStyle(
color: textColor,
fontSize: ScreenUtil().setSp(fontSize),
fontWeight:
isBold ? FontWeight.bold : FontWeight.normal),
overflow: TextOverflow.ellipsis,
)))
],
),
),
));
}
}