recharge_item.dart 18.9 KB
import 'package:cached_network_image/cached_network_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/coupon_model.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/dashed_line_widget.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/v_empty_view.dart';

import '../../../../models/recharge_list_model.dart';
import '../../../../provider/user_model.dart';
import '../../../../utils/screen_util.dart';

class RechargeItem extends StatefulWidget {
  final String from;
  final VoidCallback onPressed;
  final VoidCallback onPressedDel;
  final VoidCallback onPressedUse;
  final RechargeListSunModel rechargeListSunModel;
  final bool showBtn;
  final bool showCheck;
  RechargeItem({
    Key key,
    this.from,
    this.onPressed,
    this.onPressedDel,
    this.onPressedUse,
    this.rechargeListSunModel,
    this.showBtn = false,
    this.showCheck = false,
  }) : super(key: key);

  @override
  _RechargeItemState createState() => _RechargeItemState();
}

class _RechargeItemState extends State<RechargeItem> {
  // bool showText = false;
  @override
  Widget build(BuildContext context) {
    // CouponSunModel sunModel = widget.couponSonModel;
    bool notSelect = true;
    BoxDecoration decoration;
    if (widget.from == 'history') {
      notSelect = false;
    } else {
      // notSelect = sunModel.isOpenBool;

    }
    if (widget.from == 'menu' || widget.from == 'menu-show') {
      decoration = BoxDecoration(
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(ScreenUtil().setWidth(16)),
            topRight: Radius.circular(ScreenUtil().setWidth(16))),
        gradient: LinearGradient(stops: [
          -0.5747,
          0.5572,
          1.4872
        ], colors: [
          MyColours.color_4C8DAD,
          MyColours.color_0143A3,
          MyColours.color_42A5FF
        ], begin: Alignment.topLeft, end: Alignment.bottomRight),
      );
    } else {
      decoration = BoxDecoration(
          color: widget.from == 'history'
              ? MyColours.color_BFC4D4
              : notSelect
                  ? widget.rechargeListSunModel.isOpen == '1'
                      ? MyColours.color_438E93
                      : MyColours.color_999999
                  : MyColours.color_999999,
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(ScreenUtil().setWidth(16)),
              topRight: Radius.circular(ScreenUtil().setWidth(16))));
    }
    // double explainH = 0.0;

    // if (ObjectUtil.isNotEmpty(sunModel.explain)) {
    //   explainH = Utils.calculateTextHeight(
    //       '说明:fdgdfgdgfgsdgsg',
    //       ScreenUtil().setSp(20),
    //       FontWeight.normal,
    //       ScreenUtil().screenWidth -
    //           ScreenUtil().setWidth(92 * 2) +
    //           ScreenUtil().setWidth(20),
    //       5,
    //       context);
    // }
    return InkWell(
        onTap: widget.onPressed,
        child: Stack(
            clipBehavior: Clip.none,
            alignment: Alignment.centerLeft,
            children: [
              InkWell(
                  onTap: widget.onPressed,
                  child: Container(
                    // width: ScreenUtil().setWidth(610),
                    margin: EdgeInsets.fromLTRB(
                        ScreenUtil().setWidth(40),
                        ScreenUtil().setWidth(30),
                        ScreenUtil().setWidth(40),
                        ScreenUtil().setWidth(0)),
                    decoration: BoxDecoration(
                      color: MyColours.color_ffffff,
                      boxShadow: [
                        BoxShadow(
                            spreadRadius: ScreenUtil().setWidth(2),
                            color: Color.fromRGBO(0, 0, 0, 0.25),
                            offset: Offset(0, ScreenUtil().setWidth(8)),
                            blurRadius: ScreenUtil().setWidth(8))
                      ],
                      borderRadius: BorderRadius.all(
                        Radius.circular(ScreenUtil().setWidth(16)),
                      ),
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          height: ScreenUtil().setWidth(60),
                          padding: EdgeInsets.symmetric(
                              horizontal: ScreenUtil().setWidth(40)),
                          decoration: decoration,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                widget.rechargeListSunModel.rname,
                                style: TextStyle(
                                    color: MyColours.color_ffffff,
                                    fontWeight: FontWeight.bold,
                                    fontSize: ScreenUtil().setSp(32)),
                              ),
                              Text(
                                  '更新时间:${widget.rechargeListSunModel.cdateStr}',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: MyColours.color_ffffff,
                                      fontSize: ScreenUtil().setSp(20))),
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(20 * 2),
                              ScreenUtil().setWidth(26),
                              ScreenUtil().setWidth(40),
                              ScreenUtil().setWidth(26)),
                          child: widget.from == 'menu-show'
                              ? Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        if (widget.rechargeListSunModel
                                                .rechargeList.isPrice ==
                                            '1')
                                          Container(
                                            // height: ScreenUtil().setWidth(14 * 2),
                                            // width: ScreenUtil().setWidth(232 * 2),
                                            margin:
                                                EdgeInsets.only(bottom: w(5)),
                                            child: Text(
                                                '会员充值满${widget.rechargeListSunModel.rechargeMoney}元赠余额${widget.rechargeListSunModel.rechargeList.price}元;',
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                  color: MyColours.color_999999,
                                                  fontSize:
                                                      ScreenUtil().setSp(20),
                                                )),
                                          ),
                                        if (widget.rechargeListSunModel
                                                .rechargeList.isScore ==
                                            '1')
                                          Container(
                                            // height: ScreenUtil().setWidth(14 * 2),
                                            // width: ScreenUtil().setWidth(232 * 2),
                                            margin:
                                                EdgeInsets.only(bottom: w(5)),
                                            child: Text(
                                                '会员充值满${widget.rechargeListSunModel.rechargeMoney}元赠送${widget.rechargeListSunModel.rechargeList.score}积分;',
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                  color: MyColours.color_999999,
                                                  fontSize:
                                                      ScreenUtil().setSp(20),
                                                )),
                                          ),
                                        if (widget.rechargeListSunModel
                                                .rechargeList.isCoupons ==
                                            '1')
                                          Container(
                                            // height: ScreenUtil().setWidth(14 * 2),
                                            // width: ScreenUtil().setWidth(232 * 2),
                                            child: Text(
                                                '会员充值满${widget.rechargeListSunModel.rechargeMoney}元赠送${Utils.listToStringEnglish3(widget.rechargeListSunModel.rechargeList.couponsNames)}。',
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                  color: MyColours.color_999999,
                                                  fontSize:
                                                      ScreenUtil().setSp(20),
                                                )),
                                          ),
                                      ],
                                    ),
                                    if (widget.rechargeListSunModel.qrcode !=
                                        null)
                                      Column(
                                        children: [
                                          CachedNetworkImage(
                                            imageUrl: widget
                                                .rechargeListSunModel.qrcode,
                                            width: w(60),
                                            fit: BoxFit.cover,
                                          ),
                                          VEmptyView(10),
                                          Text(
                                            '长按识别二维码前往充值',
                                            style: TextStyle(
                                                fontSize: font(10),
                                                color: MyColours.color_999999),
                                          )
                                        ],
                                      )
                                  ],
                                )
                              : Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    if (widget.rechargeListSunModel.rechargeList
                                            .isPrice ==
                                        '1')
                                      Container(
                                        // height: ScreenUtil().setWidth(14 * 2),
                                        // width: ScreenUtil().setWidth(232 * 2),
                                        margin: EdgeInsets.only(bottom: w(5)),
                                        child: Text(
                                            '会员充值满${widget.rechargeListSunModel.rechargeMoney}元赠余额${widget.rechargeListSunModel.rechargeList.price}元;',
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: MyColours.color_999999,
                                              fontSize: ScreenUtil().setSp(20),
                                            )),
                                      ),
                                    if (widget.rechargeListSunModel.rechargeList
                                            .isScore ==
                                        '1')
                                      Container(
                                        // height: ScreenUtil().setWidth(14 * 2),
                                        // width: ScreenUtil().setWidth(232 * 2),
                                        margin: EdgeInsets.only(bottom: w(5)),
                                        child: Text(
                                            '会员充值满${widget.rechargeListSunModel.rechargeMoney}元赠送${widget.rechargeListSunModel.rechargeList.score}积分;',
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: MyColours.color_999999,
                                              fontSize: ScreenUtil().setSp(20),
                                            )),
                                      ),
                                    if (widget.rechargeListSunModel.rechargeList
                                            .isCoupons ==
                                        '1')
                                      Container(
                                        // height: ScreenUtil().setWidth(14 * 2),
                                        // width: ScreenUtil().setWidth(232 * 2),
                                        child: Text(
                                            '会员充值满${widget.rechargeListSunModel.rechargeMoney}元赠送${Utils.listToStringEnglish3(widget.rechargeListSunModel.rechargeList.couponsNames)}。',
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: MyColours.color_999999,
                                              fontSize: ScreenUtil().setSp(20),
                                            )),
                                      ),
                                  ],
                                ),

                          // widget.from == 'select'
                          //     ? widget.showCheck
                          //         ? Positioned(
                          //             right: 0,
                          //             top: ScreenUtil().setWidth(20),
                          //             child: Image.asset(
                          //               Utils.getImgPath(widget.couponSonModel.isCheck
                          //                   ? 'check_r'
                          //                   : 'check_un'),
                          //               width: ScreenUtil().setWidth(40),
                          //               height: ScreenUtil().setWidth(40),
                          //             ))
                          //         : Container()
                          //     :
                        ),
                        if (widget.showBtn)
                          MySeparator(
                              width: w(4), color: MyColours.color_BFC4D4),
                        if (widget.showBtn) VEmptyView(15),
                        if (widget.showBtn)
                          Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              RoundButton(
                                width: widget.from == 'history'
                                    ? ScreenUtil().setWidth(50 * 2)
                                    : ScreenUtil().setWidth(50 * 2),
                                height: ScreenUtil().setWidth(20 * 2),
                                radius: ScreenUtil().setWidth(10),
                                text: '删除',
                                fontSize: 24,
                                textColor: MyColours.color_E34D59,
                                gradientStart: MyColours.color_ffffff,
                                gradientEnd: MyColours.color_ffffff,
                                borderColor: MyColours.color_E34D59,
                                onPressed: widget.onPressedDel,
                              ),
                              HEmptyView(34),
                              RoundButton(
                                width: ScreenUtil().setWidth(50 * 2),
                                height: ScreenUtil().setWidth(20 * 2),
                                radius: ScreenUtil().setWidth(10),
                                text: widget.rechargeListSunModel.isOpen == '1'
                                    ? '禁用'
                                    : '启用',

                                ///启用
                                fontSize: 24,
                                textColor: MyColours.color_438E93,
                                gradientStart: MyColours.color_ffffff,
                                gradientEnd: MyColours.color_ffffff,
                                borderColor: MyColours.color_438E93,
                                onPressed: widget.onPressedUse,
                              ),
                              HEmptyView(38),
                            ],
                          ),
                        if (widget.showBtn) VEmptyView(15)
                      ],
                    ),
                  )),
              widget.showCheck
                  ? Positioned(
                      left: w(10),
                      top: ScreenUtil().setWidth(115),
                      child: Image.asset(
                        Utils.getImgPath(widget.rechargeListSunModel.isCheck
                            ? 'select_f'
                            : 'show_select_f'),
                        width: ScreenUtil().setWidth(50),
                        height: ScreenUtil().setWidth(50),
                      ))
                  : SizedBox()
            ]));
  }
}