Hibok
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.
 
 
 
 
 
 

823 regels
28 KiB

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