coupon_item.dart 15.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/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/v_empty_view.dart';

class CouponItem extends StatefulWidget {
  final String from;
  final VoidCallback onPressed;
  final VoidCallback onPressedSwich;
  final CouponSunModel couponSonModel;
  final bool showBtn;
  final bool showCheck;
  CouponItem(
      {Key key,
      this.from,
      this.onPressed,
      this.onPressedSwich,
      this.couponSonModel,
      this.showBtn = false,
      this.showCheck = false})
      : super(key: key);

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

class _CouponItemState extends State<CouponItem> {
  // bool showText = false;
  @override
  Widget build(BuildContext context) {
    CouponSunModel sunModel = widget.couponSonModel;
    bool notSelect = false;
    if (widget.from == 'history') {
      notSelect = false;
    } else {
      notSelect = sunModel.isOpenBool;
    }
    double explainH = 0.0;

    if (ObjectUtil.isNotEmpty(sunModel.explain)) {
      explainH = Utils.calculateTextHeight(
          '说明:${sunModel.explain}',
          ScreenUtil().setSp(24),
          FontWeight.normal,
          ScreenUtil.screenWidthDp - ScreenUtil().setWidth(92 * 2),
          5,
          context);
    }
    return InkWell(
      onTap: widget.onPressed,
      child: Stack(
        children: [
          Container(
            // width: ScreenUtil().setWidth(610),
            margin: EdgeInsets.fromLTRB(
                ScreenUtil().setWidth(40),
                ScreenUtil().setWidth(0),
                ScreenUtil().setWidth(40),
                ScreenUtil().setWidth(30)),
            decoration: BoxDecoration(
              boxShadow: [
                BoxShadow(
                    color: MyColours.color_EEF0F2,
                    blurRadius: ScreenUtil().setWidth(20))
              ],
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(ScreenUtil().setWidth(20)),
                topLeft: Radius.circular(ScreenUtil().setWidth(20)),
                topRight: Radius.circular(ScreenUtil().setWidth(20)),
              ),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                    width: ScreenUtil().setWidth(335 * 2 - 20),
                    padding: EdgeInsets.fromLTRB(
                        ScreenUtil().setWidth(30),
                        ScreenUtil().setWidth(26 * 2),
                        ScreenUtil().setWidth(10),
                        ScreenUtil().setWidth(20)),
                    decoration: BoxDecoration(
                      color: notSelect
                          ? MyColours.color_FFF0E5
                          : MyColours.color_f5f5f5,
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(ScreenUtil().setWidth(20)),
                        topRight: Radius.circular(0),
                        bottomLeft: ObjectUtil.isNotEmpty(sunModel.explain)
                            ? Radius.circular(0)
                            : Radius.circular(ScreenUtil().setWidth(20)),
                      ),
                    ),
                    child: Stack(
                      children: [
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                                width: ScreenUtil().setWidth(232 * 2),
                                child: Container(
                                  height: ScreenUtil().setWidth(28 * 2),
                                  constraints: BoxConstraints(
                                      maxWidth: ScreenUtil().setWidth(190)),
                                  child: Text(
                                    sunModel.aname,
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                        color: notSelect
                                            ? MyColours.color_F05522
                                            : MyColours.color_B0B0B0,
                                        fontSize: ScreenUtil().setSp(40),
                                        fontWeight: FontWeight.bold),
                                  ),
                                )),
                            Container(
                              height: ScreenUtil().setWidth(20 * 2),
                              width: ScreenUtil().setWidth(232 * 2),
                              child: Text('${sunModel.desc}',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: notSelect
                                          ? MyColours.color_F05522
                                          : MyColours.color_B0B0B0,
                                      fontSize: ScreenUtil().setSp(28),
                                      fontWeight: FontWeight.normal)),
                            ),
                            VEmptyView(20),
                            (ObjectUtil.isNotEmpty(sunModel.stime) &&
                                        sunModel.stime != '0') ||
                                    (ObjectUtil.isNotEmpty(sunModel.etime) &&
                                        sunModel.etime != '0')
                                ? Container(
                                    child: Text(
                                        '有效期:${ObjectUtil.isNotEmpty(sunModel.stime) ? Utils.getDateStrFromJiekou(sunModel.stime) : '--'} 至 ${ObjectUtil.isNotEmpty(sunModel.etime) ? Utils.getDateStrFromJiekou(sunModel.etime) : '--'}',
                                        style: TextStyle(
                                            color: notSelect
                                                ? MyColours.color_EF7249
                                                : MyColours.color_B8B8B8,
                                            fontSize: ScreenUtil().setSp(22))),
                                  )
                                : Container(),
                          ],
                        ),
                        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()
                            : Positioned(
                                right: 0,
                                top: ScreenUtil().setWidth(20),
                                child: widget.showBtn
                                    ? RoundButton(
                                        width: ScreenUtil().setWidth(58 * 2),
                                        height: ScreenUtil().setWidth(26 * 2),
                                        radius: ScreenUtil().setWidth(40),
                                        text: notSelect ? '停用' : '启用',
                                        fontSize: 28,
                                        textColor: notSelect
                                            ? MyColours.color_F05522
                                            : MyColours.color_999999,
                                        gradientStart: notSelect
                                            ? MyColours.color_FFE2D3
                                            : MyColours.color_E9E9E9,
                                        gradientEnd: notSelect
                                            ? MyColours.color_FFE2D3
                                            : MyColours.color_E9E9E9,
                                        onPressed: widget.onPressedSwich,
                                      )
                                    : Container())
                      ],
                    )),
                ObjectUtil.isNotEmpty(sunModel.explain)
                    ? InkWell(
                        onTap: () {
                          if (explainH > 19) {
                            setState(() {
                              widget.couponSonModel.showText =
                                  !widget.couponSonModel.showText;
                            });
                          }
                        },
                        child: Container(
                            width: double.infinity,
                            decoration: BoxDecoration(
                                color: notSelect
                                    ? MyColours.color_ffffff
                                    : MyColours.color_FAFAFA,
                                borderRadius: BorderRadius.only(
                                    bottomLeft: Radius.circular(
                                        ScreenUtil().setWidth(20)),
                                    bottomRight: Radius.circular(
                                        ScreenUtil().setWidth(20)))),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                widget.couponSonModel.showText
                                    ? Container(
                                        padding: EdgeInsets.fromLTRB(
                                            ScreenUtil().setWidth(30),
                                            ScreenUtil().setWidth(14),
                                            ScreenUtil().setWidth(0),
                                            ScreenUtil().setWidth(14)),
                                        width: ScreenUtil.screenWidthDp -
                                            ScreenUtil().setWidth(92 * 2),
                                        child: Text('说明:${sunModel.explain}',
                                            maxLines: 5,
                                            style: TextStyle(
                                                color: notSelect
                                                    ? MyColours.color_999999
                                                    : MyColours.color_cccccc,
                                                fontSize:
                                                    ScreenUtil().setSp(24))),
                                      )
                                    : Container(
                                        padding: EdgeInsets.fromLTRB(
                                            ScreenUtil().setWidth(30),
                                            ScreenUtil().setWidth(14),
                                            ScreenUtil().setWidth(0),
                                            ScreenUtil().setWidth(14)),
                                        width: ScreenUtil.screenWidthDp -
                                            ScreenUtil().setWidth(92 * 2) +
                                            ScreenUtil().setWidth(20),
                                        child: Text('说明:${sunModel.explain}',
                                            maxLines: 1,
                                            overflow: TextOverflow.fade,
                                            softWrap: false,
                                            style: TextStyle(
                                                color: notSelect
                                                    ? MyColours.color_999999
                                                    : MyColours.color_cccccc,
                                                fontSize:
                                                    ScreenUtil().setSp(24))),
                                      ),
                                Spacer(),
                                explainH > 19
                                    ? Container(
                                        margin: EdgeInsets.only(
                                            top: ScreenUtil().setWidth(12)),
                                        child: Image.asset(
                                            !widget.couponSonModel.showText
                                                ? Utils.getImgPath('quan_down')
                                                : Utils.getImgPath('quan_up'),
                                            width: ScreenUtil().setWidth(68),
                                            height: ScreenUtil().setWidth(44)),
                                      )
                                    : Container(),
                                HEmptyView(14)
                              ],
                            )),
                      )
                    : Container(),
              ],
            ),
          ),
          Positioned(
              top: 0,
              right: ScreenUtil().setWidth(40),
              child: Container(
                child: ObjectUtil.isNotEmpty(sunModel.explain)
                    ? Image.asset(
                        Utils.getImgPath(
                            notSelect ? 'quan_zhi' : 'quan_un_zhi'),
                        width: ScreenUtil().setWidth(20),
                        height: ScreenUtil().setWidth(109 * 2))
                    : Image.asset(
                        Utils.getImgPath(
                            notSelect ? 'quan_wan' : 'quan_un_wan'),
                        width: ScreenUtil().setWidth(20),
                        height: ScreenUtil().setWidth(109 * 2)),
              )),
          Positioned(
            top: 0,
            right: ScreenUtil().setWidth(40),
            child: InkWell(
              onTap: widget.onPressedSwich,
              child: Container(
                constraints:
                    BoxConstraints(maxWidth: ScreenUtil().setWidth(335 * 2)),
                decoration: BoxDecoration(
                    color: notSelect
                        ? MyColours.color_FFE1CB
                        : MyColours.color_EEF0F2,
                    borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(ScreenUtil().setWidth(20)),
                        topRight: Radius.circular(ScreenUtil().setWidth(20)),
                        bottomRight:
                            Radius.circular(ScreenUtil().setWidth(20)))),
                padding: EdgeInsets.symmetric(
                    horizontal: ScreenUtil().setWidth(20),
                    vertical: ScreenUtil().setWidth(2)),
                child: Text(
                    '被领取:${sunModel.receiveNum}张  已使用:${sunModel.useNum}张',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        color: notSelect
                            ? MyColours.color_EF7249
                            : MyColours.color_B7B7B7,
                        fontSize: ScreenUtil().setSp(20))),
              ),
            ),
          )
        ],
      ),
    );
  }
}