sms_recharge_page.dart
7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/sms_info.dart';
import 'package:one_key/pages/my/sms_recharge_item_page.dart';
import 'package:one_key/provider/sms_recharge_provider.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
class SmsRechargePage extends StatefulWidget {
final SmsInfoData infoData;
SmsRechargePage({Key key, this.infoData}) : super(key: key);
@override
_SmsRechargePageState createState() => _SmsRechargePageState();
}
class _SmsRechargePageState extends State<SmsRechargePage> {
ScrollController controller = ScrollController();
Meals mealsSelected;
SmsRechargeModel rechargeModel;
@override
Widget build(BuildContext context) {
rechargeModel = Provider.of<SmsRechargeModel>(context, listen: true);
return Scaffold(
backgroundColor: MyColours.color_ffffff,
appBar: SystemAppBar(
'短信充值',
onTap: () {
EventBus().emit('changeStatusColor');
Navigator.pop(context);
},
),
body: WillPopScope(
onWillPop: () async {
EventBus().emit('changeStatusColor');
return true;
},
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
controller: controller,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
VEmptyView(40),
Text(
'短信套餐',
style: TextStyle(
fontSize: ScreenUtil().setSp(38),
fontWeight: FontWeight.bold),
),
VEmptyView(30),
Text('购买套餐,使用更划算',
style: TextStyle(
fontSize: ScreenUtil().setSp(28),
color: MyColours.color_333333)),
ListView.builder(
shrinkWrap: true,
controller: controller,
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.symmetric(
vertical: ScreenUtil().setWidth(40)),
itemBuilder: (BuildContext contxt, int index) {
return SmsRechargeItemPage(
meals: widget.infoData.meals[index],
callback: () {
for (Meals item
in widget.infoData.meals) {
item.selected = false;
}
setState(() {
widget.infoData.meals[index].selected =
true;
mealsSelected =
widget.infoData.meals[index];
});
});
},
itemCount: widget.infoData.meals.length,
scrollDirection: Axis.vertical,
)
],
),
))),
Container(
height: ScreenUtil().setWidth(160),
width: double.infinity,
padding:
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(40)),
decoration: BoxDecoration(
border: Border(
top: BorderSide(
width: ScreenUtil().setWidth(2),
color: MyColours.color_E0E0E0,
))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
mealsSelected == null
? '剩余${widget.infoData.lastNum}条短信,请及时充值以保证正常使用'
: '${mealsSelected.price}元',
// maxLines: 2,
style: mealsSelected == null
? TextStyle(
fontSize: ScreenUtil().setSp(28),
color: MyColours.color_333333)
: TextStyle(
fontSize: ScreenUtil().setSp(36),
fontWeight: FontWeight.bold))),
HEmptyView(80),
RoundButton(
radius: ScreenUtil().setWidth(10),
text: '购买',
fontSize: 34,
width: ScreenUtil().setWidth(160),
height: ScreenUtil().setWidth(70),
textColor: MyColours.color_F0F0F0,
onPressed: () async {
//1.接口请求微信支付所需参数
//2.成功后掉起微信支付
Map<String, String> params;
bool success = await rechargeModel.getWechatPayInfo(
context, params);
if (success) {
//掉起微信支付
// fluwx
// .payWithWeChat(
// appId: result['appid'].toString(),
// partnerId: result['partnerid'].toString(),
// prepayId: result['prepayid'].toString(),
// packageValue: result['package'].toString(),
// nonceStr: result['noncestr'].toString(),
// timeStamp: result['timestamp'],
// sign: result['sign'].toString(),
// )
// .then((data) {
// print("---》$data");
// });
} else {
//给用户提示错误
}
},
isBold: true,
),
],
),
)
],
),
));
}
}