sms_recharge_page.dart 7.22 KB
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,
                    ),
                  ],
                ),
              )
            ],
          ),
        ));
  }
}