Hibok
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

870 rader
30 KiB

  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:chat/data/UserData.dart';
  5. import 'package:chat/data/WebData.dart';
  6. import 'package:chat/data/constants.dart';
  7. import 'package:chat/data/conversation.dart';
  8. import 'package:chat/generated/i18n.dart';
  9. import 'package:chat/home/BindBank.dart';
  10. import 'package:chat/home/ProfilePage.dart';
  11. import 'package:chat/home/rich_title.dart';
  12. import 'package:chat/models/money_change.dart';
  13. import 'package:chat/utils/ChargeMoney.dart';
  14. import 'package:chat/utils/CustomUI.dart';
  15. import 'package:chat/utils/HttpUtil.dart';
  16. import 'package:chat/utils/MessageMgr.dart';
  17. import 'package:chat/utils/TokenMgr.dart';
  18. import 'package:chat/utils/app_navigator.dart';
  19. import 'package:chat/utils/screen.dart';
  20. import 'package:dio/dio.dart';
  21. import 'package:flutter/material.dart';
  22. import 'package:flutter/services.dart';
  23. import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
  24. import 'package:flutter_screenutil/flutter_screenutil.dart';
  25. import 'package:fluwx_no_pay/fluwx_no_pay.dart' as fluwx;
  26. import 'package:oktoast/oktoast.dart';
  27. import 'package:provider/provider.dart';
  28. class _ConversationItem extends StatelessWidget {
  29. const _ConversationItem(
  30. {Key key,
  31. this.conversation,
  32. this.callback,
  33. this.showRight = true,
  34. this.rightButton,
  35. this.showReturn = false,
  36. this.applyInfo,
  37. this.bgColor,
  38. this.money,
  39. this.title})
  40. : assert(conversation != null),
  41. super(key: key);
  42. final Widget rightButton;
  43. final Conversation conversation;
  44. final callback;
  45. final int money;
  46. final bool showRight;
  47. final title;
  48. final applyInfo;
  49. final bgColor;
  50. final bool showReturn;
  51. @override
  52. Widget build(BuildContext context) {
  53. Widget avatar;
  54. double width = 44.55;
  55. if (conversation.isAvatarFromNet()) {
  56. avatar = ClipRRect(
  57. borderRadius: BorderRadius.circular(10),
  58. child: CachedNetworkImage(
  59. imageUrl: conversation.avatar,
  60. placeholder: (context, url) => Image.asset(
  61. Constants.DefaultHeadImgUrl,
  62. width: width,
  63. height: width,
  64. ),
  65. fit: BoxFit.cover,
  66. width: width,
  67. height: width,
  68. ));
  69. } else {
  70. avatar = ClipRRect(
  71. borderRadius: BorderRadius.circular(10),
  72. child: Container(
  73. width: width,
  74. height: width,
  75. alignment: Alignment.center,
  76. decoration: BoxDecoration(
  77. gradient: this.bgColor,
  78. borderRadius: BorderRadius.all(Radius.circular(50))),
  79. child: Image.asset(
  80. conversation.avatar,
  81. height: 27,
  82. )));
  83. }
  84. return InkWell(
  85. child: Container(
  86. padding:
  87. const EdgeInsets.only(left: 21, top: 9.5, bottom: 9.5, right: 24.5),
  88. decoration: BoxDecoration(
  89. color: Color(AppColors.ConversationItemBgColor),
  90. border: Border(
  91. bottom: BorderSide(
  92. color: AppColors.DividerColor,
  93. width: Constants.DividerWidth))),
  94. child: Row(
  95. crossAxisAlignment: CrossAxisAlignment.center,
  96. children: <Widget>[
  97. avatar,
  98. Container(width: 14.0),
  99. Expanded(
  100. child: Container(
  101. padding: EdgeInsets.only(top: 3),
  102. child: Column(
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children: <Widget>[
  105. Container(
  106. child: title == null
  107. ? Text(conversation.title,
  108. textScaleFactor: 1.0,
  109. style: TextStyle(
  110. fontSize: 11,
  111. color: Constants.LightGreyTextColor))
  112. : title),
  113. Container(
  114. padding: EdgeInsets.only(top: 10),
  115. child: Text(conversation.desc,
  116. textScaleFactor: 1.0,
  117. style: TextStyle(
  118. fontSize: 11, color: Constants.LightGreyTextColor)),
  119. )
  120. ],
  121. ),
  122. )),
  123. Container(
  124. height: width,
  125. margin: EdgeInsets.only(left: 10),
  126. child: Column(
  127. crossAxisAlignment: CrossAxisAlignment.end,
  128. mainAxisAlignment: MainAxisAlignment.center,
  129. children: <Widget>[
  130. Text(
  131. '${money > 0 ? '+' : ''}$money${I18n.of(context).mask_coin}',
  132. textScaleFactor: 1.0,
  133. style: TextStyle(
  134. fontSize: 14,
  135. fontWeight: FontWeight.w500,
  136. color:
  137. money > 0 ? Color(0xFFFE4624) : Color(0xFF5498FF)),
  138. ),
  139. showReturn
  140. ? Padding(
  141. padding: EdgeInsets.only(top: 3),
  142. child: Text(
  143. I18n.of(context).alreay_back,
  144. textScaleFactor: 1.0,
  145. style: TextStyle(
  146. fontSize: 12,
  147. fontWeight: FontWeight.normal,
  148. color: Constants.BlackTextColor),
  149. ))
  150. : Container()
  151. ],
  152. ),
  153. alignment: Alignment.center,
  154. ),
  155. ],
  156. ),
  157. ),
  158. onTap: () {
  159. callback();
  160. },
  161. );
  162. }
  163. }
  164. class MoneyPageOld extends StatefulWidget {
  165. MoneyPageOld({Key key}) : super(key: key);
  166. MoneyPageOldState createState() => MoneyPageOldState();
  167. }
  168. class MoneyPageOldState extends State<MoneyPageOld>
  169. with SingleTickerProviderStateMixin {
  170. List list = new List(); //列表要展示的数据
  171. ScrollController _scrollController = ScrollController(); //listview的控制器
  172. int _page = 1; //加载的页数
  173. int rows = 20;
  174. bool isLoading = false; //是否正在加载数据
  175. bool isLoadingFish = false;
  176. bool showMore = false;
  177. TabController tabCtrl;
  178. var bindAccount;
  179. messageGetBindBank(data) {
  180. getBinkInfo();
  181. }
  182. @override
  183. void initState() {
  184. super.initState();
  185. print('MoneyPageOld initState');
  186. tabCtrl = TabController(length: 2, vsync: this);
  187. getBinkInfo();
  188. MessageMgr().on('bind_bank', messageGetBindBank);
  189. fluwx.responseFromPayment.listen((data) {
  190. if (data.errCode == 0) {
  191. Navigator.of(context).pop();
  192. setState(() {});
  193. showToast(I18n.of(context).payment_successful);
  194. }
  195. });
  196. getNewData(initList);
  197. _scrollController.addListener(() {
  198. if (_scrollController.position.pixels ==
  199. _scrollController.position.maxScrollExtent) {
  200. setState(() {
  201. showMore = true;
  202. });
  203. _getMore();
  204. }
  205. });
  206. }
  207. void addList(data) {
  208. data == null || data.length == 0 ? _page-- : list.addAll(data);
  209. isLoading = false;
  210. showMore = false;
  211. setState(() {});
  212. }
  213. Future _getMore() async {
  214. if (!isLoading) {
  215. setState(() {
  216. isLoading = true;
  217. });
  218. _page++;
  219. getNewData(addList);
  220. }
  221. }
  222. void changeMoney() async {
  223. if (Provider.of<MoneyChangeProvider>(context).money < 40) {
  224. showToast(I18n.of(context).not_enough);
  225. return;
  226. }
  227. if (bindAccount == null || bindAccount['CId'] == null) {
  228. showToast(I18n.of(context).needCard);
  229. return;
  230. }
  231. if (Platform.isIOS) {
  232. AppNavigator.pushServicePage(context, questionIndex: 1);
  233. return;
  234. }
  235. String money;
  236. var confirm =
  237. CustomUI.buildConfirmBotton(I18n.of(context).determine, () async {
  238. int minMoney = 40;
  239. int maxMoney = 4000;
  240. var m = int.parse(money);
  241. if (m == null || m == 0) {
  242. showToast(I18n.of(context).enter_amount);
  243. return;
  244. }
  245. if (m > Provider.of<MoneyChangeProvider>(context).money) {
  246. showToast(I18n.of(context).not_enough);
  247. return;
  248. }
  249. if (m < minMoney) {
  250. showToast(I18n.of(context)
  251. .little_min
  252. .replaceFirst('/s1', minMoney.toString()));
  253. return;
  254. }
  255. if (m > maxMoney) {
  256. showToast(
  257. I18n.of(context).more_big.replaceFirst('/s1', maxMoney.toString()));
  258. return;
  259. }
  260. var data = {
  261. "userId": UserData().basicInfo.userId,
  262. "cId": bindAccount['CId'],
  263. "amount": m,
  264. };
  265. data['sign'] = TokenMgr().getSign(data);
  266. Response res = await HttpUtil().post('wallet/draw/order', data: data);
  267. Map resData = res.data;
  268. showToast(resData['msg']);
  269. if (resData['code'] == 0) {
  270. Navigator.of(context).pop();
  271. UserData().totalMoney -= m;
  272. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(m);
  273. MessageMgr().emit('refresh_money');
  274. _onRefresh();
  275. }
  276. });
  277. var tip = Column(
  278. children: <Widget>[
  279. Container(
  280. margin: EdgeInsets.only(top: 20),
  281. child: Text(
  282. I18n.of(context).withdrawal_application,
  283. textScaleFactor: 1.0,
  284. style: TextStyle(color: Constants.BlackTextColor, fontSize: 16),
  285. ),
  286. ),
  287. Container(
  288. margin: EdgeInsets.only(top: 23, bottom: 25),
  289. decoration: BoxDecoration(
  290. color: Colors.grey[200],
  291. borderRadius: BorderRadius.all(Radius.circular(8))),
  292. child: TextField(
  293. keyboardAppearance: Brightness.light,
  294. textAlign: TextAlign.center,
  295. textInputAction: TextInputAction.search,
  296. style:
  297. TextStyle(textBaseline: TextBaseline.alphabetic, fontSize: 14),
  298. decoration: InputDecoration(
  299. hintText: I18n.of(context).enter_amount,
  300. filled: true,
  301. contentPadding: EdgeInsets.only(top: 10, bottom: 10),
  302. fillColor: Colors.transparent,
  303. border: InputBorder.none,
  304. ),
  305. keyboardType: TextInputType.phone,
  306. maxLines: 1,
  307. inputFormatters: [
  308. WhitelistingTextInputFormatter(RegExp("^([1-9][0-9]*)\$")),
  309. WhitelistingTextInputFormatter.digitsOnly,
  310. LengthLimitingTextInputFormatter(5)
  311. ],
  312. onChanged: (str) {
  313. money = str;
  314. },
  315. ),
  316. )
  317. ],
  318. );
  319. var content = CustomUI.buildConfirmContent(tip, confirm);
  320. CustomUI.buildTip(context, '', content);
  321. }
  322. void getBinkInfo() async {
  323. Map data = {
  324. "userId": UserData().basicInfo.userId,
  325. };
  326. data['sign'] = TokenMgr().getSign(data);
  327. Response res = await HttpUtil().post('wallet/bind/bankInfo',
  328. data: data, failback: () => Navigator.of(context).pop());
  329. Map resData = res.data;
  330. if (resData['code'] == 0) {
  331. bindAccount = resData['data'];
  332. isLoadingFish = true;
  333. setState(() {});
  334. }
  335. }
  336. @override
  337. void dispose() {
  338. tabCtrl.dispose();
  339. MessageMgr().off('bind_bank', messageGetBindBank);
  340. if (_conectionSubscription != null) {
  341. _conectionSubscription.cancel();
  342. _conectionSubscription = null;
  343. }
  344. if (_purchaseUpdatedSubscription != null) {
  345. _purchaseUpdatedSubscription.cancel();
  346. _purchaseUpdatedSubscription = null;
  347. }
  348. if (_purchaseErrorSubscription != null) {
  349. _purchaseErrorSubscription.cancel();
  350. _purchaseErrorSubscription = null;
  351. }
  352. super.dispose();
  353. }
  354. @override
  355. Widget build(BuildContext context) {
  356. Widget content = Scaffold(
  357. resizeToAvoidBottomPadding: false,
  358. appBar: AppBar(
  359. backgroundColor: AppColors.NewAppbarBgColor,
  360. leading: CustomUI.buildCustomLeading(context),
  361. title: Text(
  362. I18n.of(context).wallet,
  363. textScaleFactor: 1.0,
  364. style: TextStyle(color: AppColors.NewAppbarTextColor),
  365. ),
  366. centerTitle: true,
  367. ),
  368. body: SafeArea(child: showCoin()),
  369. );
  370. return CustomUI.buildPageLoading(context, content, !isLoadingFish);
  371. }
  372. Widget _buildBindAccount() {
  373. return InkWell(
  374. onTap: () {
  375. Navigator.of(context).push(
  376. new MaterialPageRoute(
  377. builder: (context) {
  378. return BindBankPage(
  379. isBind: (bindAccount == null || bindAccount == ''),
  380. bankInfo: bindAccount,
  381. );
  382. },
  383. ),
  384. );
  385. },
  386. child: Container(
  387. decoration: BoxDecoration(
  388. color: Colors.white,
  389. border: Border(
  390. top: BorderSide(color: Colors.grey, width: 0.2),
  391. bottom: BorderSide(color: Colors.grey, width: 0.2),
  392. )),
  393. padding: EdgeInsets.only(top: 15, bottom: 15, left: 30, right: 8),
  394. child: Row(
  395. children: <Widget>[
  396. Text(
  397. I18n.of(context).bind_account.replaceFirst('/s1', ''),
  398. textScaleFactor: 1.0,
  399. style: TextStyle(fontWeight: FontWeight.normal),
  400. ),
  401. Expanded(
  402. child: Container(
  403. alignment: Alignment.centerRight,
  404. child: Row(
  405. mainAxisAlignment: MainAxisAlignment.end,
  406. children: <Widget>[
  407. (bindAccount == null || bindAccount == '')
  408. ? Container()
  409. : Text(
  410. bindAccount['Name'],
  411. textScaleFactor: 1.0,
  412. style: TextStyle(),
  413. ),
  414. Icon(
  415. IconData(0xe63c, fontFamily: 'iconfont'),
  416. size: 22.0,
  417. color: Colors.grey,
  418. )
  419. ],
  420. )),
  421. )
  422. ],
  423. ),
  424. ));
  425. }
  426. Widget _buildCard(int money2) {
  427. return Container(
  428. color: Colors.white,
  429. child: Stack(
  430. children: <Widget>[
  431. Container(
  432. margin: EdgeInsets.only(bottom: 2),
  433. color: Colors.white,
  434. width: Screen.width,
  435. child: Image.asset(
  436. 'assets/images/qianbao_bg.png',
  437. fit: BoxFit.fitWidth,
  438. ),
  439. ),
  440. Container(
  441. margin: EdgeInsets.only(top: 20, left: 25, right: 25, bottom: 20),
  442. child: Column(
  443. children: <Widget>[
  444. Padding(
  445. child: Text(
  446. '${I18n.of(context).get_way}${I18n.of(context).coin_use}',
  447. textScaleFactor: 1.0,
  448. style: TextStyle(color: Colors.white, fontSize: 10.5),
  449. ),
  450. padding: EdgeInsets.only(
  451. left: 5,
  452. right: 5,
  453. top: 13,
  454. bottom: Screen.width * 0.05),
  455. ),
  456. Row(
  457. crossAxisAlignment: CrossAxisAlignment.start,
  458. children: <Widget>[
  459. Container(
  460. child: Column(
  461. crossAxisAlignment: CrossAxisAlignment.start,
  462. children: <Widget>[
  463. Container(
  464. alignment: Alignment.centerLeft,
  465. child: Text(
  466. I18n.of(context).coin_total,
  467. textAlign: TextAlign.left,
  468. textScaleFactor: 1.0,
  469. style: TextStyle(
  470. color: Colors.white, fontSize: 15),
  471. ),
  472. padding:
  473. EdgeInsets.only(right: 5, top: 0, left: 22),
  474. ),
  475. Row(
  476. children: <Widget>[
  477. Padding(
  478. child: Container(
  479. child: Text(
  480. UserData().totalMoney.toString(),
  481. textScaleFactor: 1.0,
  482. style: TextStyle(
  483. color: Colors.white, fontSize: 31.5),
  484. ),
  485. ),
  486. padding: EdgeInsets.only(left: 25, right: 5),
  487. ),
  488. ],
  489. )
  490. ],
  491. ),
  492. ),
  493. Platform.isIOS
  494. ? Container()
  495. : Expanded(
  496. child: Container(
  497. child: Column(
  498. crossAxisAlignment: CrossAxisAlignment.start,
  499. children: <Widget>[
  500. InkWell(
  501. onTap: changeMoney,
  502. child: Container(
  503. margin: EdgeInsets.only(
  504. top: 23, right: 5),
  505. width: double.infinity,
  506. child: Row(
  507. mainAxisAlignment:
  508. MainAxisAlignment.end,
  509. children: <Widget>[
  510. Text(
  511. I18n.of(context)
  512. .exchange_cash,
  513. textScaleFactor: 1.0,
  514. style: TextStyle(
  515. color: Colors.white,
  516. fontSize: 14)),
  517. Icon(
  518. IconData(0xe63c,
  519. fontFamily: 'iconfont'),
  520. size: 20.0,
  521. color: Colors.white,
  522. ),
  523. ],
  524. ))),
  525. Container(
  526. padding: EdgeInsets.only(top: 5, right: 10),
  527. alignment: Alignment.centerRight,
  528. child: Consumer<MoneyChangeProvider>(
  529. builder: (context,
  530. MoneyChangeProvider counter,
  531. child) =>
  532. Text(
  533. '${I18n.of(context).can_withdraw} $money2',
  534. textScaleFactor: 1.0,
  535. style: TextStyle(
  536. color: Colors.white, fontSize: 12),
  537. ),
  538. ),
  539. )
  540. ],
  541. ),
  542. ))
  543. ],
  544. ),
  545. ],
  546. ),
  547. ),
  548. Positioned(
  549. bottom: 6,
  550. //left: ScreenUtil().setWidth(20),
  551. child: Platform.isIOS
  552. ? Container()
  553. : Container(
  554. //color: Colors.red,
  555. margin: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
  556. width: Screen.width - ScreenUtil().setWidth(35),
  557. child: Text(
  558. I18n.of(context).warning_text,
  559. style: TextStyle(
  560. fontSize: 11, color: const Color(0xFFFE4624)),
  561. ),
  562. ),
  563. )
  564. ],
  565. ));
  566. }
  567. Widget _buildBottomSheet() {
  568. var blueColor = AppColors.NewAppbarBgColor;
  569. return Container(
  570. height: 50,
  571. decoration: BoxDecoration(
  572. color: Constants.LightGreyBackgroundColor,
  573. border: Border(top: BorderSide(color: Color(0xffeaeaea)))),
  574. child: Row(
  575. mainAxisAlignment: Platform.isIOS
  576. ? MainAxisAlignment.center
  577. : MainAxisAlignment.spaceEvenly,
  578. children: <Widget>[
  579. InkWell(
  580. onTap: () {
  581. ChargeMoney.showChargeSheet(context, () {
  582. setState(() {});
  583. });
  584. },
  585. child: Container(
  586. width: MediaQuery.of(context).size.width / 2,
  587. alignment: Alignment.center,
  588. child: Row(
  589. mainAxisAlignment: MainAxisAlignment.center,
  590. children: <Widget>[
  591. Icon(
  592. IconData(
  593. 0xe642,
  594. fontFamily: 'iconfont',
  595. ),
  596. color: blueColor,
  597. ),
  598. SizedBox(width: 7.5),
  599. Text(
  600. I18n.of(context).recharge,
  601. textScaleFactor: 1.0,
  602. style: TextStyle(color: blueColor),
  603. ),
  604. ],
  605. ))),
  606. Platform.isIOS
  607. ? Container()
  608. : InkWell(
  609. onTap: changeMoney,
  610. child: Container(
  611. width: MediaQuery.of(context).size.width / 2,
  612. alignment: Alignment.center,
  613. child: Row(
  614. mainAxisAlignment: MainAxisAlignment.center,
  615. children: <Widget>[
  616. Icon(
  617. IconData(
  618. 0xe64a,
  619. fontFamily: 'iconfont',
  620. ),
  621. color: blueColor,
  622. ),
  623. SizedBox(width: 7.5),
  624. Text(
  625. Platform.isIOS
  626. ? '咨询客服'
  627. : I18n.of(context).exchange_cash,
  628. textScaleFactor: 1.0,
  629. style: TextStyle(color: blueColor),
  630. ),
  631. ],
  632. )))
  633. ],
  634. ),
  635. );
  636. }
  637. Widget showCoin() {
  638. return Scaffold(
  639. bottomNavigationBar: _buildBottomSheet(),
  640. body: SafeArea(
  641. child: Center(
  642. child: Container(
  643. height: MediaQuery.of(context).size.height,
  644. width: MediaQuery.of(context).size.width,
  645. child: _buildCoinBody(),
  646. ),
  647. )));
  648. }
  649. /*
  650. * 下拉刷新方法,为list重新赋值
  651. */
  652. Future<Null> _onRefresh() async {
  653. _page = 1;
  654. _scrollController.jumpTo(0);
  655. getNewData(initList);
  656. }
  657. void initList(data) {
  658. list.clear();
  659. if (data != null) {
  660. list.addAll(data);
  661. }
  662. isLoadingFish = true;
  663. setState(() {});
  664. }
  665. getNewData(callback) async {
  666. Map data = {
  667. "userId": UserData().basicInfo.userId,
  668. };
  669. data['sign'] = TokenMgr().getSign(data);
  670. data["page"] = _page;
  671. data['rows'] = rows;
  672. data['type'] = 2;
  673. Response res = await HttpUtil().post('message/wallet/message', data: data);
  674. var resData = res.data;
  675. print(resData);
  676. if (resData['code'] == 0) {
  677. callback(resData['data']);
  678. } else {
  679. showToast(resData['msg']);
  680. }
  681. }
  682. bool isAdd(bool isMyself, int type) {
  683. return type == 1 ||
  684. type == 10 ||
  685. type == 11 ||
  686. (!isMyself && type == 3) ||
  687. (!isMyself && type == 4) ||
  688. (!isMyself && type == 7) ||
  689. (!isMyself && type == 8) ||
  690. (!isMyself && type == 9);
  691. }
  692. //钱包通知
  693. Widget _buildMoneyInfo(data) {
  694. bool isMyself = data['UserId'] == UserData().basicInfo.userId;
  695. String imgUrl = data['HeadImg'] == null || data['HeadImg'] == ''
  696. ? UserData().basicInfo.headimgurl
  697. : data['HeadImg'];
  698. return _ConversationItem(
  699. conversation: Conversation(
  700. avatar: imgUrl,
  701. title: '',
  702. desc: WebData().getLoginTime(context, data['CreateTime']),
  703. updateAt: '',
  704. ),
  705. bgColor: Constants.MoneyGradient,
  706. showReturn: data['DetailType'] == 10 ||
  707. data['Status'] == 2 ||
  708. (data['DetailType'] != 9 &&
  709. data['DetailType'] != 6 &&
  710. data['Status'] == 1),
  711. money:
  712. isAdd(isMyself, data['DetailType']) ? data['Value'] : -data['Value'],
  713. title: RichTitle.getRichTitleWidget(data, context, InfoType.IncomeMoney,
  714. titleStyle: TextStyle(fontSize: 12, color: const Color(0XFF7F7F7F)),
  715. nameStyle: TextStyle(
  716. fontWeight: FontWeight.normal,
  717. fontSize: 13,
  718. color: Constants.BlackTextColor)),
  719. callback: () {
  720. if (data['ChangeUserId'] != 0) {
  721. Navigator.of(context).push(
  722. new MaterialPageRoute(
  723. builder: (context) {
  724. return ProfilePage(
  725. userId: data['UserId'] == UserData().basicInfo.userId
  726. ? data['ChangeUserId']
  727. : data['UserId'],
  728. );
  729. },
  730. ),
  731. );
  732. }
  733. },
  734. );
  735. }
  736. Widget _renderRow(BuildContext context, int index) {
  737. if (list.length == 0) {
  738. return Column(
  739. children: <Widget>[
  740. _buildCard(Provider.of<MoneyChangeProvider>(context).money),
  741. // _buildBindAccount(),
  742. ],
  743. );
  744. }
  745. if (index < list.length) {
  746. var userInfo = list[index];
  747. Widget result = _buildMoneyInfo(userInfo);
  748. if (index == 0) {
  749. result = Column(
  750. children: <Widget>[
  751. _buildCard(Provider.of<MoneyChangeProvider>(context).money),
  752. Platform.isIOS ? Container() : _buildBindAccount(),
  753. Padding(padding: EdgeInsets.only(top: 10), child: result)
  754. ],
  755. );
  756. }
  757. return result;
  758. } else if (showMore) {
  759. _getMoreWidget();
  760. }
  761. return Container();
  762. }
  763. Widget _getMoreWidget() {
  764. return Center(
  765. child: CircularProgressIndicator(
  766. valueColor: AlwaysStoppedAnimation(Constants.BlueTextColor)));
  767. }
  768. Widget _buildCoinBody() {
  769. return RefreshIndicator(
  770. onRefresh: _onRefresh,
  771. child: ListView.builder(
  772. physics: AlwaysScrollableScrollPhysics(),
  773. itemBuilder: _renderRow,
  774. itemCount: list.length + 1,
  775. controller: _scrollController,
  776. ),
  777. );
  778. }
  779. static String currentGoodsId = '';
  780. static StreamSubscription _conectionSubscription,
  781. _purchaseUpdatedSubscription,
  782. _purchaseErrorSubscription;
  783. ///ios 内购初始化
  784. static Future initPayConf(BuildContext context) async {
  785. if (_purchaseErrorSubscription != null) {
  786. return;
  787. }
  788. // prepare
  789. print('initPayConf -------- start: ');
  790. var result = await FlutterInappPurchase.instance.initConnection;
  791. print('initPayConf -------- result: $result');
  792. FlutterInappPurchase.instance.clearTransactionIOS();
  793. _conectionSubscription =
  794. FlutterInappPurchase.connectionUpdated.listen((connected) {
  795. print('connected: $connected');
  796. });
  797. _purchaseUpdatedSubscription =
  798. FlutterInappPurchase.purchaseUpdated.listen((productItem) {
  799. print('支付成功,成功回调 ------ purchase-updated: $productItem');
  800. // showToast('支付成功,成功回调 ------ purchase-updated: $productItem');
  801. if (productItem.transactionReceipt != null &&
  802. productItem.transactionReceipt.isNotEmpty) {
  803. HttpUtil().createOrder(currentGoodsId, productItem.transactionReceipt,
  804. productItem.purchaseToken,
  805. context: context);
  806. showToast(I18n.of(context).payment_successful);
  807. }
  808. Navigator.of(context).pop();
  809. });
  810. _purchaseErrorSubscription =
  811. FlutterInappPurchase.purchaseError.listen((purchaseError) {
  812. // showToast('支付失败回调 -------- purchase-error: $purchaseError');
  813. FlutterInappPurchase.instance.clearTransactionIOS();
  814. Navigator.of(context).pop();
  815. });
  816. }
  817. }