Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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