123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- import 'dart:async';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_alipay/flutter_alipay.dart';
- import 'package:fluwx/fluwx.dart';
- import 'package:ysairplane2/base/YSBase.dart';
- import 'package:ysairplane2/code/YSBill.dart';
- import 'package:ysairplane2/tools/YSNetWorking.dart';
- import 'package:ysairplane2/tools/YSTools.dart';
- import 'package:fluwx/fluwx.dart' as fluwx;
- class YSMoney extends StatefulWidget {
- @override
- _YSMoneyState createState() => _YSMoneyState();
- }
- class _YSMoneyState extends State<YSMoney> {
- List array = ['支付宝','微信'];
- int _selected = 0;
- bool _isSucceed = false;
- List _dataArray = [];
- String _psyStr = '支付宝';
- TextEditingController _amountField = TextEditingController();
- StreamSubscription _listener;
- @override
- void dispose() {
- _listener.cancel();
- super.dispose();
- }
- @override
- void initState() {
- _listener = fluwx.weChatResponseEventHandler.listen((res) {
- if (res is fluwx.WeChatPaymentResponse) {
- print('---------------->${res.errCode}');
- if(res.isSuccessful==true){
- }
- }
- });
- Future.delayed(Duration(seconds: 0)).then((value){
- _getBalancePackData();
- });
- super.initState();
- }
- String _balanceStr = '0.00';
- @override
- Widget build(BuildContext context) {
- return YSBase(
- ystitle: '钱包',
- ysright: GestureDetector(
- child: Text('账单',style: TextStyle(fontSize: zsp(34),color: Color(0xFF131318)),),
- onTap: (){
- Navigator.of(context).push(
- CupertinoPageRoute(
- builder: (context){
- return YSBill();
- }
- )
- );
- },
- ),
- yschild: Container(
- height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
- width: MediaQuery.of(context).size.width,
- color: Color(0xFFF5F6F8),
- child: SingleChildScrollView(
- child: _isSucceed==true?Column(
- children: [
- Container(
- color: Colors.white,
- width: MediaQuery.of(context).size.width,
- padding: EdgeInsets.only(left: wsp(30),right: wsp(30),top: hsp(60),bottom: hsp(60)),
- child: Column(
- children: [
- Image(
- image: AssetImage('lib/images/succeed.png'),
- height: hsp(130),
- width: wsp(130)
- ),
- Container(
- child: Text('充值成功',style: TextStyle(fontSize: zsp(40),color: Color(0xFF333333)),),
- margin: EdgeInsets.only(top: hsp(40),bottom: hsp(33)),
- ),
- Text('本次充值可用金额1100元',style: TextStyle(fontSize: zsp(28),color: Color(0xFF878787)),),
- ],
- ),
- ),
- GestureDetector(
- onTap: (){
- setState(() {
- _isSucceed = false;
- });
- },
- child: Container(
- height: hsp(94),
- width: MediaQuery.of(context).size.width-wsp(24)*2,
- alignment: Alignment.center,
- margin: EdgeInsets.only(top: hsp(58)),
- decoration: BoxDecoration(
- color: Color(0xFF0079FF),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Text('完成',style: TextStyle(color: Colors.white,fontSize: zsp(34)),),
- ),
- )
- ],
- ):Column(
- children: [
- Container(
- margin: EdgeInsets.only(left: wsp(24),right: wsp(24),bottom: hsp(24),top: hsp(18)),
- height: hsp(240),
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage('lib/images/top.png'),
- fit: BoxFit.fill
- ),
- ),
- child: Stack(
- children: [
- Container(
- margin: EdgeInsets.only(left: wsp(46),top: hsp(65)),
- child: Row(
- children: [
- Text('可用余额(RMB) ',style: TextStyle(fontSize: zsp(24),color: Colors.white),),
- Image(image: AssetImage('lib/images/eyes2.png'),color: Colors.white,height: hsp(21),width: wsp(28),)
- ],
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: wsp(48),top: hsp(120)),
- child: Text('$_balanceStr',style: TextStyle(fontSize: zsp(68),color: Colors.white,fontWeight: FontWeight.bold),),
- )
- ],
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: wsp(24),right: wsp(24),bottom: hsp(14)),
- width: MediaQuery.of(context).size.width-wsp(48),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- padding: EdgeInsets.only(left: wsp(40),right: wsp(40),top: hsp(26),bottom: hsp(26)),
- decoration: BoxDecoration(
- border: Border(bottom: BorderSide(color: Color(0xFFF5F5F7),width: hsp (1)))
- ),
- child: Text('优惠活动',style: TextStyle(fontSize: zsp(30)),),
- ),
- Container(
- height: hsp(370),
- margin: EdgeInsets.only(left: wsp(34),right: wsp(34),top: hsp(40),bottom: hsp(40)),
- child: GridView.builder(
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3,
- crossAxisSpacing: wsp(20),
- mainAxisSpacing: hsp(20),
- childAspectRatio: wsp(198)/hsp(110)
- ),
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- setState(() {
- _selected = index;
- });
- },
- child: index==_dataArray.length?Container(
- height: hsp(110),
- decoration: BoxDecoration(
- color: Color(0xFFF5F7F7),
- border: Border.all(color: index==_selected?Color(0xFF0079FF):Colors.transparent,width: 0.5),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Center(child: Text('其他金额',style: TextStyle(fontSize: zsp(26),color: Color(0xFF999999)),)),
- ):Container(
- padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15)),
- height: hsp(110),
- decoration: BoxDecoration(
- color: Color(0xFFF5F7F7),
- border: Border.all(color: index==_selected?Color(0xFF0079FF):Colors.transparent,width: 0.5),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- Image(height: hsp(26),width: wsp(26),image: AssetImage('lib/images/money2.png')),
- Text(' ${_dataArray[index]['name']}',style: TextStyle(fontSize: zsp(30),fontWeight: FontWeight.bold,color: Color(0xFF181818)),)
- ],
- mainAxisSize: MainAxisSize.min,
- ),
- Text('${_dataArray[index]['des']}',style: TextStyle(fontSize: zsp(20),color: Color(0xFF999999)),)
- ],
- ),
- ),
- );
- },
- itemCount: _dataArray.length+1,
- physics: NeverScrollableScrollPhysics(),
- ),
- ),
- if(_selected==_dataArray.length)Container(
- width: MediaQuery.of(context).size.width,
- margin: EdgeInsets.only(left: wsp(34),right: wsp(34),bottom: hsp(22)),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text('转入金额',style: TextStyle(fontSize: zsp(28),color: Color(0xFF333333)),),
- Container(
- height: hsp(100),
- decoration: BoxDecoration(
- border: Border(bottom: BorderSide(color: Color(0xFFEEEEEE),width: 0.5))
- ),
- child: CupertinoTextField(
- decoration: BoxDecoration(),
- prefix: Text('\n¥',style: TextStyle(fontSize: zsp(36),color: Color(0xFF333333)),),
- style: TextStyle(fontSize: zsp(60),color: Color(0xFF333333),fontWeight: FontWeight.bold),
- keyboardType: TextInputType.number,
- suffix: Image(image: AssetImage('lib/images/off2.png'),height: 20,width: 20,),
- controller: _amountField,
- ),
- )
- ],
- ),
- ),
- // Container(
- // margin: EdgeInsets.only(left: wsp(34),right: wsp(34),bottom: hsp(49)),
- // child: Row(
- // children: [
- // Text('充值即代表同意',style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)),),
- // Text('《某某充值协议》',style: TextStyle(fontSize: zsp(22),color: Color(0xFF0079FF),fontWeight: FontWeight.bold),)
- // ],
- // ),
- // )
- ],
- ),
- ),
- Container(
- height: hsp(92),
- width: MediaQuery.of(context).size.width-wsp(48),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- padding: EdgeInsets.only(left: wsp(30),right: wsp(30)),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text('支付方式',style: TextStyle(fontSize: zsp(32),color: Color(0xFF000000)),),
- DropdownButton(
- value: _psyStr,
- items: [
- for(int i=0;i<array.length;i++)DropdownMenuItem(child: Text('${array[i]}'),value: '${array[i]}',),
- ],
- onChanged: (value){
- setState(() {
- _psyStr = value;
- });
- },
- underline: Container(),
- icon: Icon(Icons.keyboard_arrow_down,size: zsp(30),color: Color(0xFF999999),),
- style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),
- )
- ],
- ),
- ),
- GestureDetector(
- onTap: (){
- _postBalanceOrderData();
- },
- child: Container(
- height: hsp(90),
- width: MediaQuery.of(context).size.width-wsp(24)*2,
- alignment: Alignment.center,
- margin: EdgeInsets.only(top: hsp(65)),
- decoration: BoxDecoration(
- color: Color(0xFF0079FF),
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- child: Text('充值',style: TextStyle(color: Colors.white,fontSize: zsp(34)),),
- ),
- )
- ],
- ),
- ),
- ),
- );
- }
- _getBalancePackData() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/balance/getBalancePack',parameter: {},isLoading: true,
- isToken: true,refresh: (){_getBalancePackData();});
- if(dict!=null){
- setState(() {
- _balanceStr = '${dict['data']['blance']}';
- _dataArray = dict['data']['balancePack'];
- });
- }
- }
- _postBalanceOrderData() async{
- Map request = {};
- request['way'] = _psyStr=='支付宝'?3:2;
- request['type'] = 1;
- if(_selected==_dataArray.length){
- if(_amountField.text.isEmpty){
- ysFlutterToast(context, '请输入充值金额 ');
- return;
- }
- request['price'] = _amountField.text;
- }else{
- request['id'] = _dataArray[_selected]['id'];
- }
- Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/createPayOrder',
- parameter: request,isLoading: true,
- isToken: true,refresh: (){_getBalancePackData();});
- if(dict!=null){
- if(_psyStr=='支付宝'){
- var payResult = await FlutterAlipay.pay('${dict['data']}');
- String payResultStatus = payResult.resultStatus;
- if (payResultStatus == "9000") {
- print('=================================订单支付成功');
- } else if (payResultStatus == "6001") {
- print('=================================支付取消');
- } else if (payResultStatus == "4000") {
- print('=================================支付失败');
- } else if (payResultStatus == "8000") {
- print('=================================等待支付');
- } else if (payResultStatus == "6002") {
- print('=================================无网络');
- } else if (payResultStatus == "5000") {
- print('=================================重复支付');
- } else {
- print('=================================支付失败,未知错误');
- }
- }else{
- Map result = dict['data'];
- fluwx.payWithWeChat(
- appId: result['appId'].toString(),
- partnerId: result['partnerId'].toString(),
- prepayId: result['prepayId'].toString(),
- packageValue: result['package'].toString(),
- nonceStr: result['nonceStr'].toString(),
- timeStamp: int.parse('${result['timeStamp']}'),
- sign: result['paySign'].toString(),
- // appId: "wx7e62294a5bf6e206",
- // partnerId: "1609486954",
- // prepayId: "wx08190939522528a0fac5616807982f0000",
- // packageValue: "Sign=WXPay",
- // nonceStr: "01NYog3p0Ptz8JMW",
- // timeStamp: int.parse('1623150580'),
- // sign: "565D7E49DBC2BA60F63715D16F2FEA49",
- ).then((data) {});
- }
- }
- }
- }
|