Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 849993f

Browse files
添加WeUIButtonTheme和WeUIButtonThemeData
1 parent 6e646d9 commit 849993f

File tree

3 files changed

+210
-3
lines changed

3 files changed

+210
-3
lines changed

‎lib/src/base/button_theme.dart‎

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_weui/src/base/global.dart';
3+
4+
class WeUIButtonTheme extends InheritedWidget {
5+
static WeUIButtonThemeData of(BuildContext context) {
6+
final WeUIButtonTheme buttonTheme = context.inheritFromWidgetOfExactType(WeUIButtonTheme);
7+
return buttonTheme?.data;
8+
}
9+
10+
WeUIButtonTheme({
11+
Brightness brightness = Brightness.light,
12+
double btnWidth = 184,
13+
double btnHeight = 40,
14+
double btnFontSize = 17,
15+
double btnBorderRadius = 4,
16+
double btnDefaultGap = 16,
17+
double btnMiniFontSize = 16,
18+
double btnMiniHeight = 32,
19+
double btnCellHeight = 56,
20+
double btnCellGap = 16,
21+
Color btnFontColor,
22+
Color btnDisabledFontColor,
23+
Color btnDisabledBg,
24+
Color btnDefaultFontColor,
25+
Color btnDefaultDisabledFontColor,
26+
Color btnDefaultBg,
27+
Color btnDefaultActiveBg,
28+
Color btnDefaultDisabledBg,
29+
Widget child,
30+
Key key,
31+
}) : data = WeUIButtonThemeData(
32+
btnWidth: btnWidth,
33+
btnHeight: btnHeight,
34+
btnFontSize: btnFontSize,
35+
btnBorderRadius: btnBorderRadius,
36+
btnDefaultGap: btnDefaultGap,
37+
btnMiniFontSize: btnMiniFontSize,
38+
btnMiniHeight: btnMiniHeight,
39+
btnCellHeight: btnCellHeight,
40+
btnCellGap: btnCellGap,
41+
btnFontColor: btnFontColor,
42+
btnDisabledFontColor: btnDisabledFontColor,
43+
btnDisabledBg: btnDisabledBg,
44+
btnDefaultFontColor: btnDefaultFontColor,
45+
btnDefaultDisabledFontColor: btnDefaultDisabledFontColor,
46+
btnDefaultBg: btnDefaultBg,
47+
btnDefaultActiveBg: btnDefaultActiveBg,
48+
btnDefaultDisabledBg: btnDefaultDisabledBg,
49+
),
50+
super(child: child, key: key);
51+
final WeUIButtonThemeData data;
52+
53+
@override
54+
bool updateShouldNotify(WeUIButtonTheme oldWidget) => this.data != oldWidget.data;
55+
}
56+
57+
class WeUIButtonThemeData {
58+
factory WeUIButtonThemeData({
59+
Brightness brightness,
60+
double btnWidth = 184,
61+
double btnHeight = 40,
62+
double btnFontSize = 17,
63+
double btnBorderRadius = 4,
64+
double btnDefaultGap = 16,
65+
double btnMiniFontSize = 16,
66+
double btnMiniHeight = 32,
67+
double btnCellHeight = 56,
68+
double btnCellGap = 16,
69+
Color btnFontColor,
70+
Color btnDisabledFontColor,
71+
Color btnDisabledBg,
72+
Color btnDefaultFontColor,
73+
Color btnDefaultDisabledFontColor,
74+
Color btnDefaultBg,
75+
Color btnDefaultActiveBg,
76+
Color btnDefaultDisabledBg,
77+
Color btnPrimaryFontColor,
78+
Color btnPrimaryDisabledFontColor,
79+
Color btnPrimaryBg,
80+
Color btnPrimaryActiveBg,
81+
Color btnPrimaryDisabledBg,
82+
Color btnWarnFontColor,
83+
Color btnWarnDisabledFontColor,
84+
Color btnWarnBg,
85+
Color btnWarnActiveBg,
86+
Color btnwarnDisabledBg,
87+
}) {
88+
brightness ??= Brightness.light;
89+
btnFontColor ??= weuiBtnFontColor(brightness);
90+
btnDisabledFontColor ??= weuiBtnDisabledFontColor(brightness);
91+
btnDisabledBg ??= weuiBtnDisabledBg(brightness);
92+
btnDefaultFontColor ??= weuiBtnDefaultFontColor(brightness);
93+
btnDefaultDisabledFontColor ??= weuiBtnDefaultDisabledFontColor(brightness);
94+
btnDefaultBg ??= weuiBtnDefaultDisabledBg(brightness);
95+
btnDefaultActiveBg ??= weuiBtnDefaultActiveBg(brightness);
96+
btnDefaultDisabledBg ??= weuiBtnDefaultDisabledBg(brightness);
97+
btnPrimaryFontColor ??= weuiBtnFontColor(brightness);
98+
btnPrimaryDisabledFontColor ??= weuiBtnDisabledFontColor(brightness);
99+
btnPrimaryBg ??= weuiBtnPrimaryBg(brightness);
100+
btnPrimaryActiveBg ??= weuiBtnPrimaryActiveBg(brightness);
101+
btnPrimaryDisabledBg ??= weuiBtnPrimaryDisabledBg(brightness);
102+
btnWarnFontColor ??= weuiBtnWarnFontColor(brightness);
103+
btnWarnDisabledFontColor ??= weuiBtnDisabledFontColor(brightness);
104+
btnWarnBg ??= weuiBtnWarnBg(brightness);
105+
btnWarnActiveBg ??= weuiBtnWarnActiveBg(brightness);
106+
btnwarnDisabledBg ??= weuiBtnwarnDisabledBg(brightness);
107+
return WeUIButtonThemeData.raw(
108+
btnWidth: btnWidth,
109+
btnHeight: btnHeight,
110+
btnFontSize: btnFontSize,
111+
btnBorderRadius: btnBorderRadius,
112+
btnDefaultGap: btnDefaultGap,
113+
btnMiniFontSize: btnMiniFontSize,
114+
btnMiniHeight: btnMiniHeight,
115+
btnCellHeight: btnCellHeight,
116+
btnCellGap: btnCellGap,
117+
btnFontColor: btnFontColor,
118+
btnDisabledFontColor: btnDisabledFontColor,
119+
btnDisabledBg: btnDisabledBg,
120+
btnDefaultFontColor: btnDefaultFontColor,
121+
btnDefaultDisabledFontColor: btnDefaultDisabledFontColor,
122+
btnDefaultBg: btnDefaultBg,
123+
btnDefaultActiveBg: btnDefaultActiveBg,
124+
btnDefaultDisabledBg: btnDefaultDisabledBg,
125+
btnPrimaryFontColor: btnPrimaryFontColor,
126+
btnPrimaryDisabledFontColor: btnPrimaryDisabledFontColor,
127+
btnPrimaryBg: btnPrimaryBg,
128+
btnPrimaryActiveBg: btnPrimaryActiveBg,
129+
btnPrimaryDisabledBg: btnPrimaryDisabledBg,
130+
btnWarnFontColor: btnWarnFontColor,
131+
btnWarnDisabledFontColor: btnWarnDisabledFontColor,
132+
btnWarnBg: btnWarnBg,
133+
btnWarnActiveBg: btnWarnActiveBg,
134+
btnwarnDisabledBg: btnwarnDisabledBg,
135+
);
136+
}
137+
138+
factory WeUIButtonThemeData.light() => WeUIButtonThemeData(brightness: Brightness.light);
139+
140+
factory WeUIButtonThemeData.dark() => WeUIButtonThemeData(brightness: Brightness.dark);
141+
142+
WeUIButtonThemeData.raw({
143+
@required this.btnWidth,
144+
@required this.btnHeight,
145+
@required this.btnFontSize,
146+
@required this.btnBorderRadius,
147+
@required this.btnDefaultGap,
148+
@required this.btnMiniFontSize,
149+
@required this.btnMiniHeight,
150+
@required this.btnCellHeight,
151+
@required this.btnCellGap,
152+
@required this.btnFontColor,
153+
@required this.btnDisabledFontColor,
154+
@required this.btnDisabledBg,
155+
@required this.btnDefaultFontColor,
156+
@required this.btnDefaultDisabledFontColor,
157+
@required this.btnDefaultBg,
158+
@required this.btnDefaultActiveBg,
159+
@required this.btnDefaultDisabledBg,
160+
@required this.btnPrimaryFontColor,
161+
@required this.btnPrimaryDisabledFontColor,
162+
@required this.btnPrimaryBg,
163+
@required this.btnPrimaryActiveBg,
164+
@required this.btnPrimaryDisabledBg,
165+
@required this.btnWarnFontColor,
166+
@required this.btnWarnDisabledFontColor,
167+
@required this.btnWarnBg,
168+
@required this.btnWarnActiveBg,
169+
@required this.btnwarnDisabledBg,
170+
}) : btnCellLineHeight = (btnCellHeight - 2 * btnCellGap) / btnFontSize;
171+
final double btnWidth;
172+
final double btnHeight;
173+
final double btnFontSize;
174+
final double btnBorderRadius;
175+
final double btnDefaultGap;
176+
final double btnMiniFontSize;
177+
final double btnMiniHeight;
178+
final double btnCellHeight;
179+
final double btnCellGap;
180+
double btnCellLineHeight;
181+
final Color btnFontColor;
182+
final Color btnDisabledFontColor;
183+
final Color btnDisabledBg;
184+
final Color btnDefaultFontColor;
185+
final Color btnDefaultDisabledFontColor;
186+
final Color btnDefaultBg;
187+
final Color btnDefaultActiveBg;
188+
final Color btnDefaultDisabledBg;
189+
final Color btnPrimaryFontColor;
190+
final Color btnPrimaryDisabledFontColor;
191+
final Color btnPrimaryBg;
192+
final Color btnPrimaryActiveBg;
193+
final Color btnPrimaryDisabledBg;
194+
final Color btnWarnFontColor;
195+
final Color btnWarnDisabledFontColor;
196+
final Color btnWarnBg;
197+
final Color btnWarnActiveBg;
198+
final Color btnwarnDisabledBg;
199+
}

‎lib/src/base/global.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ Color weuiBtnDisabledFontColor(Brightness brightness) => themeColor(
7777
ColorFunction weuiBtnDisabledBg = weuiBtnDefaultBg;
7878

7979
// // default
80-
Color weuiBtnDefaultColor(Brightness brightness) => themeColor(brightness,
80+
Color weuiBtnDefaultFontColor(Brightness brightness) => themeColor(brightness,
8181
SmartColor.parse("#06ae56"), SmartColor.parse("rgba(255, 255, 255, 0.8)"));
82-
// ColorFunction weuiBtnDefaultDisabledFontColor=weuiBtnDisabledFontColor;
82+
ColorFunction weuiBtnDefaultDisabledFontColor=weuiBtnDisabledFontColor;
8383
Color weuiBtnDefaultBg(Brightness brightness) => themeColor(brightness,
8484
SmartColor.parse("#f2f2f2"), SmartColor.parse("rgba(255, 255, 255, 0.08)"));
8585
Color weuiBtnDefaultActiveBg(Brightness brightness) => themeColor(

‎lib/src/base/theme.dart‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_weui/src/base/button_theme.dart';
34
import 'package:flutter_weui/src/base/color.dart';
45
import 'package:smart_color/smart_color.dart';
56

@@ -148,6 +149,7 @@ class WeUIThemeData extends Diagnosticable {
148149
Brightness brightness,
149150
Color textTipsColor,
150151
Color linkDefaultColor,
152+
WeUIButtonThemeData buttonTheme,
151153
}){
152154
brightness ??= Brightness.light;
153155
textTipsColor ??= weuiTextColorTips(brightness);
@@ -163,6 +165,7 @@ class WeUIThemeData extends Diagnosticable {
163165
textTitleColor ??= weuiTextColorTitle(brightness);
164166
textDescColor ??= weuiTextColorDesc(brightness);
165167
textWarnColor ??= weuiTextColorWarn(brightness);
168+
buttonTheme ??= WeUIButtonThemeData(brightness: brightness);
166169
return WeUIThemeData.raw(
167170
brightness: brightness,
168171
textTipsColor: textTipsColor,
@@ -178,6 +181,7 @@ class WeUIThemeData extends Diagnosticable {
178181
textDescColor: textDescColor,
179182
textTitleColor: textTitleColor,
180183
textWarnColor: textWarnColor,
184+
buttonTheme: buttonTheme,
181185
);
182186
}
183187
const WeUIThemeData.raw({
@@ -195,6 +199,7 @@ class WeUIThemeData extends Diagnosticable {
195199
@required this.brightness,
196200
@required this.textTipsColor,
197201
@required this.linkDefaultColor,
202+
@required this.buttonTheme,
198203
});
199204
final Color primaryColor;
200205
final Color warnColor;
@@ -210,8 +215,11 @@ class WeUIThemeData extends Diagnosticable {
210215
final Color textTitleColor;
211216
final Color textDescColor;
212217
final Color textWarnColor;
218+
final WeUIButtonThemeData buttonTheme;
213219

214-
factory WeUIThemeData.light() => null;
220+
factory WeUIThemeData.light() => WeUIThemeData(brightness: Brightness.light);
221+
222+
factory WeUIThemeData.dark() => WeUIThemeData(brightness: Brightness.dark);
215223
}
216224

217225
class _InheritedTheme extends InheritedWidget {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /