基础组件库
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

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