import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; class YSWithdrawal extends StatefulWidget { const YSWithdrawal({Key key}) : super(key: key); @override _YSWithdrawalState createState() => _YSWithdrawalState(); } class _YSWithdrawalState extends State { //wexinLogo aliLogo List _typeArray = [{'img':'wexinLogo','title':''},{'img':'aliLogo','title':''}]; int _selectedIndex = 0; double _balance = 0.00; TextEditingController _amountField = TextEditingController(); @override void dispose() { _amountField.dispose(); super.dispose(); } @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getWithdrawalData(); }); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( appBar: CupertinoNavigationBar( leading: GestureDetector( onTap: (){Navigator.pop(context);}, child: Icon(Icons.arrow_back_ios,size: 20,color: Color(0xFF000000),), ), middle: Text('提现',style: TextStyle(color: Color(0xFF000000),fontSize: 16, decoration: TextDecoration.none,fontWeight: FontWeight.w600),textAlign: TextAlign.center,), backgroundColor: Color(0xFFF5F6F8), border: Border.all(color: Colors.transparent,width: hsp(1)), ), backgroundColor: Color(0xFFF5F6F8), body: SingleChildScrollView( child: Container( width: MediaQuery.of(context).size.width, child: Column( children: [ Container( height: hsp(150), padding: EdgeInsets.only(left: hsp(30),right: hsp(30)), child: GestureDetector( onTap: (){ FocusScope.of(context).unfocus(); int selectedIndex = _selectedIndex; showModalBottomSheet( context: context, builder: (context){ return Container( height: hsp(500), child: Column( children: [ Container( height: hsp(99), child: Row( children: [ Container(width: hsp(40),), Text('选择提现账号',style: TextStyle(fontSize: zsp(30),color: Colors.black),), GestureDetector( onTap: (){Navigator.pop(context);}, child: Icon(Icons.close,size: hsp(40),color: Colors.black,), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), ), Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF5F6F8),), StatefulBuilder( builder: (context,chooseSet){ return Container( height: hsp(300), child: ListView.separated( padding: EdgeInsets.only(left: hsp(30),right: hsp(30)), itemBuilder: (context,index){ Map item = _typeArray[index]; return GestureDetector( onTap: (){ chooseSet(() { selectedIndex = index; }); }, behavior: HitTestBehavior.opaque, child: Container( height: hsp(100), child: Row( children: [ Image.asset('lib/images/${item['img']}.png',height: hsp(40),width: hsp(40),), Container( width: MediaQuery.of(context).size.width-hsp(140), padding: EdgeInsets.only(left: hsp(20),right: hsp(20)), child: Text('${item['title']}',style: TextStyle(fontSize: zsp(30),color: Colors.black),), ), Icon(selectedIndex==index?Icons.check_circle:Icons.radio_button_unchecked, size: hsp(40),color: Color(selectedIndex==index?0xFF007AFF:0xFFCCCCCC),), ], ), ), ); }, separatorBuilder: (context,index){ return Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF5F6F8),); }, itemCount: _typeArray.length, ), ); }, ), GestureDetector( child: Container( height: hsp(80), margin: EdgeInsets.only(left: hsp(30),right: hsp(30)), decoration: BoxDecoration( color: Color(0xFF007AFF), borderRadius: BorderRadius.all(Radius.circular(5)) ), alignment: Alignment.center, child: Text('确认',style: TextStyle(fontSize: zsp(30),color: Colors.white),), ), onTap: (){ Navigator.pop(context); _selectedIndex = selectedIndex; setState(() {}); }, ) ], ), ); } ); }, child: Row( children: [ Text('到账账号:',style: TextStyle(fontSize: zsp(30),color: Colors.black),), Image.asset('lib/images/${_typeArray[_selectedIndex]['img']}.png',height: hsp(40),width: hsp(40),), ConstrainedBox( constraints: BoxConstraints( maxWidth: MediaQuery.of(context).size.width/2 ), child: Text(' ${_typeArray[_selectedIndex]['title']} ',style: TextStyle(fontSize: zsp(30),color: Colors.black),maxLines: 1,), ), Icon(Icons.keyboard_arrow_down,size: hsp(40),color: Color(0xFFCCCCCC),) ], ), ), ), Container( width: MediaQuery.of(context).size.width, padding: EdgeInsets.all(hsp(30)), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10)) ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('提现金额',style: TextStyle(fontSize: zsp(30),color: Colors.black),), Container( margin: EdgeInsets.only(top: hsp(30),bottom: hsp(30)), height: hsp(100), child: CupertinoTextField( placeholder: '', decoration: BoxDecoration(), style: TextStyle(fontSize: zsp(60),color: Colors.black,fontWeight: FontWeight.bold), prefix: Text('¥',style: TextStyle(fontSize: zsp(40),color: Colors.black,fontWeight: FontWeight.bold),), keyboardType: TextInputType.number, inputFormatters: [NumberFormat()], controller: _amountField, ), ), RichText( text: TextSpan( text: '可提现金额:', style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)), children: [ TextSpan( text: '¥$_balance', style: TextStyle(color: Colors.black) ) ] ), ), GestureDetector( onTap: (){ _postWithdrawalData(); }, child: Container( height: hsp(88), margin: EdgeInsets.only(left: hsp(40),right: hsp(40),top: hsp(60),bottom: hsp(30)), decoration: BoxDecoration( color: Color(0xFF007AFF), borderRadius: BorderRadius.all(Radius.circular(5)) ), alignment: Alignment.center, child: Text('提现',style: TextStyle(fontSize: zsp(32),color: Colors.white),), ), ) ], ), ) ], ), ), ), ); } _getWithdrawalData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/withDrawInfo',parameter: {},isLoading: false,isToken: true); if(dict!=null){ _typeArray[0]['title'] = dict['data']['paymentAccountWx']; _typeArray[1]['title'] = dict['data']['paymentAccountAlipay']; _balance = dict['data']['balance']*1.0; setState(() {}); } } _postWithdrawalData() async{ if(_amountField.text.isEmpty){ ysFlutterToast(context, '请输入提现金额'); return; } double amount = double.parse(_amountField.text); if(amount>_balance){ ysFlutterToast(context, '提现金额不能大于余额'); return; } Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/commitWithDraw', parameter: {'paymentAccountWay':_selectedIndex==0?2:3,'price':amount},isLoading: true,isToken: true); if(dict!=null){ ysFlutterToast(context, '已提交提现申请'); Navigator.of(context).pop(''); } } }