|
| 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 | +} |
0 commit comments