123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_alipay/flutter_alipay.dart';
- import 'package:ysairplane2/tools/YSNetWorking.dart';
- import 'package:ysairplane2/tools/YSPayKeybord.dart';
- import 'package:ysairplane2/tools/YSTools.dart';
- import 'package:fluwx/fluwx.dart' as fluwx;
- import 'YSMoney.dart';
- import 'YSSetPayPass.dart';
- class YSPayTypeView extends StatefulWidget {
- final Map orderDict;
- final VoidCallback postSuccess;
- const YSPayTypeView({Key key, this.orderDict, this.postSuccess}) : super(key: key);
- @override
- _YSPayTypeViewState createState() => _YSPayTypeViewState();
- }
- class _YSPayTypeViewState extends State<YSPayTypeView> {
- int _selected = 0;
- @override
- void initState() {
- fluwx.weChatResponseEventHandler.listen((res) {
- if (res is fluwx.WeChatPaymentResponse) {
- if(res.isSuccessful==true){
- widget.postSuccess();
- }
- }
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- height: hsp(600),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
- ),
- child: Column(
- children: [
- Container(
- height: hsp(99),
- decoration: BoxDecoration(
- border: Border(bottom: BorderSide(color: Color(0xFFD8D8D8),width: hsp(1)))
- ),
- padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
- alignment: Alignment.center,
- child: Text('支付方式',style: TextStyle(fontSize: zsp(30),color: Color(0xFF4A4A4A),fontWeight: FontWeight.bold),),
- ),
- Container(
- height: hsp(400),
- child: ListView.separated(
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- setState(() {
- _selected = index;
- });
- },
- behavior: HitTestBehavior.opaque,
- child: Container(
- height: hsp(99),
- color: Colors.white,
- padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- Container(
- height: hsp(50),
- width: hsp(50),
- margin: EdgeInsets.only(right: hsp(25)),
- child: Image.asset(index==0?'lib/images/余额.png':index==1?'lib/images/wexinLogo.png':'lib/images/aliLogo.png'),
- ),
- Text(index==0?'余额':index==1?'微信支付':'支付宝',style: TextStyle(fontSize: zsp(30),color: Color(0xFF343434),)),
- ],
- ),
- Icon(index==_selected?Icons.check_circle:Icons.radio_button_unchecked,size: hsp(40),
- color: Color(index==_selected?0xFF007EFF:0xFF9B9B9B),)
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF1F2F3),);
- },
- itemCount: 3,
- padding: EdgeInsets.all(0),
- physics: NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- )
- ,
- ),
- GestureDetector(
- onTap: (){
- _postOrderData();
- },
- child: Container(
- height: hsp(100),
- color: Color(0xFFFD2A2E),
- alignment: Alignment.center,
- child: Text('确认支付',style: TextStyle(fontSize: zsp(30),color: Colors.white,fontWeight: FontWeight.bold),),
- ),
- )
- ],
- ),
- );
- }
- _showAlertView (int type) async{
- showCupertinoDialog(
- context: context,
- builder: (context) {
- return CupertinoAlertDialog(
- title: Text('提示\n'),
- content: Text(type==1?'未设置支付密码':'余额不足请充值'),
- actions: <Widget>[
- CupertinoDialogAction(child: Text('取消'),onPressed: (){Navigator.pop(context);},),
- CupertinoDialogAction(child: Text(type==1?'去设置':'去充值'),onPressed: (){
- Navigator.pop(context);
- Navigator.of(context).push(
- CupertinoPageRoute(
- builder: (context){
- return type==1?YSSetPayPass():YSMoney();
- }
- )
- );
- },),
- ],
- );
- }
- );
- }
- _postPayData(String pass) async{
- var dict = await ysRequestHttpEncrypt(context,type: requestType.post,api: '/app/applets/balance/balancePay',
- parameter: {'orderSn':widget.orderDict['orderSn'],'price':widget.orderDict['price'],'password': pass},isLoading: true,isToken: true);
- if(dict!=null){
- if(dict==''){
- widget.postSuccess();
- }else if(dict['code']==804){
- _showAlertView(2);
- }else if(dict['code']==801){
- _showAlertView(1);
- }
- }
- }
- _postOrderData() async{
- if(_selected==0){
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/balance/wx/checkBalance',parameter: {},isLoading: true,isToken: true,
- refresh: (){});
- if(dict!=null){
- if(dict['code']==801){
- _showAlertView(1);
- }else{
- showDialog(context: context,builder: (context){
- return AlertDialog(
- contentPadding: EdgeInsets.all(0),
- actionsPadding: EdgeInsets.all(0),
- buttonPadding: EdgeInsets.all(0),
- insetPadding: EdgeInsets.all(0),
- titlePadding: EdgeInsets.all(0),
- backgroundColor: Colors.transparent,
- content: ysPayKeybord(context,(value){
- _postPayData(value);
- },'${widget.orderDict['orderName']}',
- '${widget.orderDict['price']}')
- );
- });
- }
- }
- }else{
- Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/createPayOrder',
- parameter: {'id':widget.orderDict['orderSn'],'way':_selected+1,'type':2},isLoading: true,
- isToken: true,refresh: (){});
- if(dict!=null){
- if(_selected==2){
- var payResult = await FlutterAlipay.pay('${dict['data']}');
- String payResultStatus = payResult.resultStatus;
- if (payResultStatus == "9000") {
- print('=================================订单支付成功');
- widget.postSuccess();
- } 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 if(_selected==1){
- 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(),
- ).then((data) {});
- }
- }
- }
- }
- }
|