基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

372 lines
11 KiB

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:zhiying_base_widget/pages/withdraw_page/bloc/withdraw_bloc.dart';
  5. import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_model.dart';
  6. import 'package:zhiying_base_widget/pages/withdraw_page/withdraw_page_sk.dart';
  7. import 'package:zhiying_comm/util/base_bloc.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. /*提现页面*/
  10. class WithdrawPage extends StatefulWidget {
  11. final Map<String, dynamic> data;
  12. const WithdrawPage(this.data, {Key key}) : super(key: key);
  13. @override
  14. _WithdrawPageState createState() => _WithdrawPageState();
  15. }
  16. class _WithdrawPageState extends State<WithdrawPage> {
  17. @override
  18. Widget build(BuildContext context) {
  19. return GestureDetector(
  20. onTap: () {
  21. FocusScope.of(context).requestFocus(FocusNode());
  22. },
  23. child: Scaffold(
  24. appBar: _createNav(),
  25. backgroundColor: Colors.white,
  26. body: SafeArea(
  27. child: BlocProvider<WithdrawBloc>(
  28. bloc: WithdrawBloc(),
  29. child: _WithdrawContainer(widget.data),
  30. ),
  31. ),
  32. ),
  33. );
  34. }
  35. // 导航栏
  36. Widget _createNav() {
  37. return CupertinoNavigationBar(
  38. leading: Navigator.canPop(context)
  39. ? GestureDetector(
  40. child: Container(
  41. padding: EdgeInsets.zero,
  42. child: Icon(
  43. Icons.arrow_back_ios,
  44. size: 20,
  45. ),
  46. ),
  47. onTap: () {
  48. if (Navigator.canPop(context)) {
  49. Navigator.pop(context);
  50. }
  51. },
  52. )
  53. : Container(),
  54. middle: Text(
  55. '提现',
  56. style: TextStyle(
  57. fontSize: 15,
  58. color: Color(0xff333333),
  59. ),
  60. ),
  61. trailing: GestureDetector(
  62. child: Text(
  63. '明细',
  64. style: TextStyle(fontSize: 13, color: Color(0xff333333)),
  65. ),
  66. onTap: () {},
  67. ),
  68. );
  69. }
  70. }
  71. class _WithdrawContainer extends StatefulWidget {
  72. final Map<String, dynamic> data;
  73. const _WithdrawContainer(this.data, {Key key}) : super(key: key);
  74. @override
  75. _WithdrawContainerState createState() => _WithdrawContainerState();
  76. }
  77. class _WithdrawContainerState extends State<_WithdrawContainer> {
  78. WithdrawBloc _bloc;
  79. int _currentIndex = 0;
  80. TextEditingController _controller = TextEditingController();
  81. bool _submitable = false;
  82. bool _inputable = false;
  83. @override
  84. void initState() {
  85. _bloc = BlocProvider.of<WithdrawBloc>(context);
  86. if (widget.data.containsKey('skip_identifier')) {
  87. _bloc.loadData(widget.data['skip_identifier']);
  88. }
  89. super.initState();
  90. }
  91. @override
  92. Widget build(BuildContext context) {
  93. return SingleChildScrollView(
  94. child: StreamBuilder<WithdrawModel>(
  95. stream: _bloc.outData,
  96. builder: (BuildContext context, AsyncSnapshot snapshot) {
  97. WithdrawModel model = snapshot.data;
  98. if (model == null) {
  99. return WithdrawPageSketelon();
  100. }
  101. return Container(
  102. margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 8),
  103. child: Column(
  104. children: <Widget>[
  105. _createHeader(model),
  106. _createVerify(model),
  107. _createPrice(model),
  108. _createInput(model),
  109. _createSubmit(model),
  110. _createDesc(model),
  111. ],
  112. ),
  113. );
  114. }),
  115. // child: Column(
  116. // children: <Widget>[],
  117. // ),
  118. );
  119. }
  120. Widget _createHeader(WithdrawModel model) {
  121. return Container(
  122. width: double.infinity,
  123. height: 97,
  124. decoration: BoxDecoration(
  125. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  126. child: Stack(
  127. children: <Widget>[
  128. Container(
  129. width: double.infinity,
  130. height: double.infinity,
  131. child: CachedNetworkImage(
  132. imageUrl: model.availableCashOutBgImg ?? '',
  133. fit: BoxFit.fill,
  134. ),
  135. ),
  136. Center(
  137. child: Column(
  138. mainAxisAlignment: MainAxisAlignment.center,
  139. children: <Widget>[
  140. Text(
  141. '¥0.03',
  142. style: TextStyle(
  143. color: Colors.white,
  144. fontSize: 30,
  145. ),
  146. ),
  147. Text(
  148. '可提现总余额',
  149. style: TextStyle(
  150. color: Colors.white,
  151. fontSize: 14,
  152. ),
  153. ),
  154. ],
  155. ),
  156. )
  157. ],
  158. ),
  159. );
  160. }
  161. Widget _createVerify(WithdrawModel model) {
  162. return GestureDetector(
  163. behavior: HitTestBehavior.opaque,
  164. onTap: () {
  165. Logger.debug('绑定支付宝');
  166. },
  167. child: Container(
  168. margin: EdgeInsets.only(top: 8, bottom: 8),
  169. child: Row(
  170. children: <Widget>[
  171. CachedNetworkImage(
  172. imageUrl: model.unbindAlipayImg,
  173. height: 23,
  174. ),
  175. Expanded(
  176. child: Padding(
  177. padding: const EdgeInsets.only(left: 8, right: 8),
  178. child: Text(
  179. model.unbindAlipayText,
  180. style: TextStyle(fontSize: 11, color: Color(0xff999999)),
  181. ),
  182. ),
  183. ),
  184. Icon(
  185. Icons.arrow_forward_ios,
  186. size: 12,
  187. color: Color(0xff999999),
  188. )
  189. ],
  190. ),
  191. ),
  192. );
  193. }
  194. Widget _createPrice(WithdrawModel model) {
  195. return GridView.builder(
  196. shrinkWrap: true,
  197. physics: NeverScrollableScrollPhysics(),
  198. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  199. crossAxisCount: 3,
  200. crossAxisSpacing: 10,
  201. mainAxisSpacing: 10,
  202. childAspectRatio: 2.5,
  203. ),
  204. itemCount: model?.cashOutDashbordItems?.length ?? 0,
  205. itemBuilder: (BuildContext context, int index) {
  206. WithdrawDashbordItems item = model.cashOutDashbordItems[index];
  207. return GestureDetector(
  208. onTap: () {
  209. _controller.text = item.value;
  210. _currentIndex = index;
  211. _inputable = item.value == null || item.value == '';
  212. _checkSubmit(item.value);
  213. },
  214. child: Container(
  215. decoration: BoxDecoration(
  216. color: index == _currentIndex
  217. ? HexColor.fromHex(
  218. model.cashOutDashbordItemsSelectedBgColor ?? '')
  219. : HexColor.fromHex(
  220. model.cashOutDashbordItemsUnselectedBgColor ?? ''),
  221. borderRadius: BorderRadius.circular(5),
  222. border: Border.all(
  223. color: index == _currentIndex
  224. ? HexColor.fromHex(
  225. model.cashOutDashbordItemsSelectedColor ?? '')
  226. : HexColor.fromHex('#d2d2d2'),
  227. ),
  228. ),
  229. child: Center(
  230. child: Text(
  231. item.name,
  232. style: TextStyle(
  233. fontSize: 14,
  234. color: index == _currentIndex
  235. ? HexColor.fromHex(
  236. model.cashOutDashbordItemsSelectedColor ?? '')
  237. : HexColor.fromHex(
  238. model.cashOutDashbordItemsUnselectedColor ?? ''),
  239. ),
  240. ),
  241. ),
  242. ),
  243. );
  244. },
  245. );
  246. }
  247. Widget _createInput(WithdrawModel model) {
  248. return Padding(
  249. padding: const EdgeInsets.only(top: 8.0),
  250. child: Column(
  251. crossAxisAlignment: CrossAxisAlignment.start,
  252. mainAxisAlignment: MainAxisAlignment.start,
  253. children: <Widget>[
  254. Text(
  255. '提现金额',
  256. style: TextStyle(
  257. fontWeight: FontWeight.bold,
  258. color: Color(0xff333333),
  259. ),
  260. ),
  261. Container(
  262. width: double.infinity,
  263. height: 50,
  264. child: CupertinoTextField(
  265. placeholder: '输入提现金额',
  266. controller: _controller,
  267. enabled: _inputable,
  268. style: TextStyle(
  269. fontSize: 30,
  270. color: Color(0xff333333),
  271. fontFamily: 'Din-Bold',
  272. package: 'zhiying_base_widget',
  273. ),
  274. decoration: BoxDecoration(color: Colors.transparent),
  275. keyboardType: TextInputType.numberWithOptions(decimal: true),
  276. textInputAction: TextInputAction.done,
  277. inputFormatters: [
  278. WhitelistingTextInputFormatter(RegExp("[0-9.]")), //只允许输入小数
  279. ],
  280. prefix: Text(
  281. '¥',
  282. style: TextStyle(fontSize: 20),
  283. ),
  284. onChanged: (value) {
  285. _checkSubmit(value);
  286. },
  287. ),
  288. ),
  289. Container(
  290. margin: EdgeInsets.only(top: 5, bottom: 20),
  291. width: double.infinity,
  292. height: 0.5,
  293. color: Color(0xffe4e4e4),
  294. ),
  295. ],
  296. ),
  297. );
  298. }
  299. Widget _createSubmit(WithdrawModel model) {
  300. return Container(
  301. height: 50,
  302. decoration: BoxDecoration(
  303. color: _submitable
  304. ? HexColor.fromHex(model.cashOutBtnTextAvailableBgColor ?? '')
  305. : HexColor.fromHex(model.cashOutBtnTextUnavailableBgColor ?? ''),
  306. borderRadius: BorderRadius.circular(7.5),
  307. ),
  308. child: Center(
  309. child: Text(
  310. model.cashOutBtnText ?? '',
  311. style: TextStyle(
  312. fontSize: 15,
  313. color: _submitable
  314. ? HexColor.fromHex(model.cashOutBtnTextAvailableColor ?? '')
  315. : HexColor.fromHex(model.cashOutBtnTextUnavailableColor ?? ''),
  316. ),
  317. ),
  318. ),
  319. );
  320. }
  321. Widget _createDesc(WithdrawModel model) {
  322. return Column(
  323. crossAxisAlignment: CrossAxisAlignment.start,
  324. mainAxisAlignment: MainAxisAlignment.start,
  325. children: <Widget>[
  326. Container(
  327. width: double.infinity,
  328. margin: EdgeInsets.only(top: 8),
  329. child: Text(
  330. '提现说明',
  331. style: TextStyle(
  332. fontWeight: FontWeight.bold,
  333. color: Color(0xff333333),
  334. ),
  335. ),
  336. ),
  337. Text(
  338. model.cashOutTips ?? '',
  339. style: TextStyle(
  340. color: Color(0xff999999),
  341. fontSize: 14,
  342. ),
  343. ),
  344. ],
  345. );
  346. }
  347. void _checkSubmit(String value) {
  348. _submitable = value.length > 0;
  349. setState(() {});
  350. }
  351. }