Hibok
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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