common_button.dart
3.04 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
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
class CommonButton extends StatelessWidget {
final VoidCallback onPress;
final String content;
final double width;
final double height;
final double fontSize;
final int state; //-1 不可用 0 默认 1 选中
final FontWeight fontWeight;
CommonButton(
{@required this.onPress,
@required this.content,
this.state = 0,
this.width = 250,
this.height = 50,
this.fontSize = 18,
this.fontWeight = FontWeight.normal});
@override
Widget build(BuildContext context) {
BoxDecoration boxDecoration;
Color fontColor;
switch (state) {
case -1:
boxDecoration = BoxDecoration(
color: MyColours.color_74BBBE,
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
);
fontColor = MyColours.color_ffffff;
break;
case 0:
boxDecoration = BoxDecoration(
border: Border.all(
color: MyColours.color_199095, width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
);
fontColor = MyColours.color_199095;
break;
case 1:
boxDecoration = BoxDecoration(
color: MyColours.color_199095,
// gradient: LinearGradient(
// colors: [Color(0xff199095), Color(0xff36C3C7)],
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter),
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
);
fontColor = MyColours.color_fefefe;
break;
case 2:
boxDecoration = BoxDecoration(
color: MyColours.color_199095,
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
);
fontColor = MyColours.color_fefefe;
break;
case -2:
boxDecoration = BoxDecoration(
color: MyColours.color_74BBBE,
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
);
fontColor = MyColours.color_fefefe;
break;
default:
boxDecoration = BoxDecoration(
border: Border.all(color: MyColours.color_199095),
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
);
fontColor = MyColours.color_fefefe;
break;
break;
}
return Material(
child: Ink(
child: InkWell(
onTap: onPress,
child: Container(
width: ScreenUtil().setWidth(width),
height: ScreenUtil().setWidth(height),
decoration: boxDecoration,
child: Align(
alignment: Alignment.center,
child: Text(
content,
style: TextStyle(
color: fontColor,
fontWeight: fontWeight,
fontSize: ScreenUtil().setSp(fontSize)),
),
),
),
),
),
);
}
}