recharge_item.dart 12.8 KB
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;
    if (widget.from == 'history') {
      notSelect = false;
    } else {
      // notSelect = sunModel.isOpenBool;
    }
    // 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: 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)))),
                          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: 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()
            ]));
  }
}