|
|
|
@ -1,11 +1,19 @@
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
|
import 'package:fluwx/fluwx.dart'; |
|
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/wx_pay.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
|
|
|
import 'package:huixiang/utils/min.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/item_input_widget.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
|
|
|
|
|
class RechargePage extends StatefulWidget { |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
|
return _RechargePage(); |
|
|
|
@ -13,10 +21,22 @@ class RechargePage extends StatefulWidget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _RechargePage extends State<RechargePage> { |
|
|
|
|
TextEditingController controller; |
|
|
|
|
ApiService apiService; |
|
|
|
|
|
|
|
|
|
TextEditingController controller = TextEditingController(); |
|
|
|
|
|
|
|
|
|
Color color = Colors.black; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
|
|
|
|
|
|
SharedPreferences.getInstance().then((value) { |
|
|
|
|
apiService = ApiService(Dio(), |
|
|
|
|
context: context, token: value.getString("token"), pay: true); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
return Scaffold( |
|
|
|
@ -26,7 +46,7 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
fontSize: 18, |
|
|
|
|
fontSize: 18.sp, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
centerTitle: false, |
|
|
|
@ -38,7 +58,7 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
alignment: Alignment.centerRight, |
|
|
|
|
margin: EdgeInsets.only(left: 10), |
|
|
|
|
margin: EdgeInsets.only(left: 10.w), |
|
|
|
|
padding: EdgeInsets.all(6), |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.arrow_back_ios, |
|
|
|
@ -48,7 +68,7 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
titleSpacing: 2, |
|
|
|
|
leadingWidth: 56, |
|
|
|
|
leadingWidth: 56.w, |
|
|
|
|
), |
|
|
|
|
body: SingleChildScrollView( |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
@ -67,9 +87,13 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
errorTextColor: Color(0xFF32A060), |
|
|
|
|
radius: 8, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontWeight: FontWeight.bold, fontSize: 30.sp, color: color), |
|
|
|
|
inputLimit: 16, |
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
fontSize: 30.sp, |
|
|
|
|
color: color, |
|
|
|
|
), |
|
|
|
|
inputLimit: 12, |
|
|
|
|
textInputType: TextInputType.number, |
|
|
|
|
textInputFormatter: FilteringTextInputFormatter.digitsOnly, |
|
|
|
|
onChanged: (value) { |
|
|
|
|
if (value != null && |
|
|
|
|
value != "" && |
|
|
|
@ -83,10 +107,18 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
margin: |
|
|
|
|
EdgeInsets.only(left: 20, right: 20, top: 12, bottom: 4), |
|
|
|
|
padding: |
|
|
|
|
EdgeInsets.only(left: 20, right: 16, top: 20, bottom: 20), |
|
|
|
|
margin: EdgeInsets.only( |
|
|
|
|
left: 20.w, |
|
|
|
|
right: 20.w, |
|
|
|
|
top: 12.h, |
|
|
|
|
bottom: 4.h, |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.only( |
|
|
|
|
left: 20.w, |
|
|
|
|
right: 16.w, |
|
|
|
|
top: 20.h, |
|
|
|
|
bottom: 20.h, |
|
|
|
|
), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
@ -105,17 +137,23 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(bottom: 16), |
|
|
|
|
padding: EdgeInsets.only(bottom: 16.h), |
|
|
|
|
child: Text( |
|
|
|
|
S.of(context).zhifufangshi, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 16, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
color: color, |
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Row( |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
checkIndex = 0; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
@ -123,18 +161,27 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
Expanded( |
|
|
|
|
flex: 1, |
|
|
|
|
child: Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 8, bottom: 20), |
|
|
|
|
child: Text(S.of(context).zhifubao, |
|
|
|
|
padding: EdgeInsets.only(left: 8.w, bottom: 20.h), |
|
|
|
|
child: Text( |
|
|
|
|
S.of(context).zhifubao, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Color(0xff353535), |
|
|
|
|
)), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
checkView(0), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
Row( |
|
|
|
|
), |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
checkIndex = 1; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
@ -142,63 +189,99 @@ class _RechargePage extends State<RechargePage> {
|
|
|
|
|
Expanded( |
|
|
|
|
flex: 1, |
|
|
|
|
child: Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 8), |
|
|
|
|
padding: EdgeInsets.only(left: 8.w), |
|
|
|
|
child: Text(S.of(context).weixinzhifu, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Color(0xff353535), |
|
|
|
|
)), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
checkView(1), |
|
|
|
|
], |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
margin: EdgeInsets.only(left: 20, right: 20, top: 26), |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () { |
|
|
|
|
recharge(); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 26.h), |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
RoundButton( |
|
|
|
|
width: double.infinity, |
|
|
|
|
height: 46, |
|
|
|
|
text:S.of(context).querenchongzhi, |
|
|
|
|
height: 46.h, |
|
|
|
|
text: S.of(context).querenchongzhi, |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontSize: 14, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
backgroup: Color(0xff32A060), |
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var checkIndex = 0; |
|
|
|
|
|
|
|
|
|
Widget checkView(var index) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
checkIndex = index; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
padding: EdgeInsets.only(right: 16), |
|
|
|
|
return Container( |
|
|
|
|
padding: EdgeInsets.only(right: 16.w), |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: Image.asset( |
|
|
|
|
checkIndex != index |
|
|
|
|
? "assets/image/icon_radio_unselected.png" |
|
|
|
|
: "assets/image/icon_radio_selected.png", |
|
|
|
|
width: 15, |
|
|
|
|
height: 15, |
|
|
|
|
)), |
|
|
|
|
width: 15.w, |
|
|
|
|
height: 15.h, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
recharge() async { |
|
|
|
|
String money = controller.text; |
|
|
|
|
if (money == null || money == "") { |
|
|
|
|
SmartDialog.showToast(S.of(context).qingshuruchongzhijine); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
int amount = int.tryParse(money); |
|
|
|
|
if (checkIndex == 1) { |
|
|
|
|
if (!(await Min.isInitialize())) { |
|
|
|
|
// 小程序的微信支付和app的充值支付使用同一个WXPayEntryActivity回调, |
|
|
|
|
// 然而充值时小程序未初始化会导致回调内部代码调用getPackage空指针, |
|
|
|
|
// 故而在此初始化一下 |
|
|
|
|
await Min.initialize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BaseData baseData = |
|
|
|
|
await apiService.recharge({"amount": amount, "rechargeType": 2}); |
|
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
|
WxPay wxPay = WxPay.fromJson(baseData.data); |
|
|
|
|
await registerWxApi(appId: wxPay.appId, doOnAndroid: true, universalLink: "https://hx.lotus-wallet.com/app/"); |
|
|
|
|
payWithWeChat( |
|
|
|
|
appId: wxPay.appId, |
|
|
|
|
partnerId: wxPay.partnerId, |
|
|
|
|
prepayId: wxPay.prepayId, |
|
|
|
|
packageValue: wxPay.packageValue, |
|
|
|
|
nonceStr: wxPay.nonceStr, |
|
|
|
|
timeStamp: int.tryParse(wxPay.timeStamp), |
|
|
|
|
sign: wxPay.sign); |
|
|
|
|
weChatResponseEventHandler.listen((event) async { |
|
|
|
|
print("payCallback: ${event.errCode}"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|