coupon_item.dart 7.05 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;
  CouponItem(
      {Key key,
      this.from,
      this.onPressed,
      this.onPressedSwich,
      this.couponSonModel,
      this.showBtn = false})
      : super(key: key);

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

class _CouponItemState extends State<CouponItem> {
  @override
  Widget build(BuildContext context) {
    CouponSunModel sunModel = widget.couponSonModel;
    bool notSelect = false;
    if (widget.from == 'history') {
      notSelect = false;
    } else {
      notSelect = sunModel.isOpenBool;
    }
    return InkWell(
      onTap: widget.onPressed,
      child: Stack(
        children: [
          Container(
            // width: ScreenUtil().setWidth(610),
            margin: EdgeInsets.symmetric(
                horizontal: ScreenUtil().setWidth(30),
                vertical: ScreenUtil().setWidth(12)),
            padding: EdgeInsets.all(ScreenUtil().setWidth(30)),
            decoration: BoxDecoration(
                color: notSelect ? MyColours.app_main : MyColours.color_E0E0E0,
                borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10))),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: ScreenUtil().setWidth(360),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Container(
                        constraints: BoxConstraints(
                            maxWidth: ScreenUtil().setWidth(190)),
                        child: Text(
                          sunModel.aname,
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              color: MyColours.color_ffffff,
                              fontSize: ScreenUtil().setSp(34),
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                      Expanded(
                          flex: 1,
                          child: Container(
                            padding: EdgeInsets.only(
                                bottom: ScreenUtil().setWidth(6)),
                            child: Text('( ${sunModel.desc} )',
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    color: MyColours.color_ffffff,
                                    fontSize: ScreenUtil().setSp(22),
                                    fontWeight: FontWeight.bold)),
                          ))
                    ],
                  ),
                ),
                ObjectUtil.isNotEmpty(sunModel.explain)
                    ? Container(
                        margin: EdgeInsets.only(top: ScreenUtil().setWidth(30)),
                        padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
                        width: double.infinity,
                        child: Text('说明:${sunModel.explain}',
                            maxLines: 30,
                            overflow: TextOverflow.ellipsis,
                            softWrap: false,
                            style: TextStyle(
                                color: notSelect
                                    ? MyColours.app_main
                                    : MyColours.color_e5e5e5,
                                fontSize: ScreenUtil().setSp(22))),
                        decoration: BoxDecoration(
                            color: MyColours.color_ffffff,
                            borderRadius: BorderRadius.circular(
                                ScreenUtil().setWidth(10))),
                      )
                    : Container(),
                (ObjectUtil.isNotEmpty(sunModel.stime) &&
                            sunModel.stime != '0') ||
                        (ObjectUtil.isNotEmpty(sunModel.etime) &&
                            sunModel.etime != '0')
                    ? Container(
                        padding:
                            EdgeInsets.only(top: ScreenUtil().setWidth(20)),
                        child: Text(
                            '有效期:${ObjectUtil.isNotEmpty(sunModel.stime) ? Utils.getDateStrFromJiekou(sunModel.stime) : '--'} 至 ${ObjectUtil.isNotEmpty(sunModel.etime) ? Utils.getDateStrFromJiekou(sunModel.etime) : '--'}',
                            style: TextStyle(
                                color: MyColours.color_ffffff,
                                fontSize: ScreenUtil().setSp(22))),
                      )
                    : Container(),
              ],
            ),
          ),
          Positioned(
            top: ScreenUtil().setWidth(30),
            right: ScreenUtil().setWidth(60),
            child: InkWell(
              onTap: widget.onPressedSwich,
              child: Row(
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('被领取:${sunModel.receiveNum}张',
                          style: TextStyle(
                              color: MyColours.color_ffffff,
                              fontSize: ScreenUtil().setSp(22))),
                      VEmptyView(5),
                      Text('已使用:${sunModel.useNum}张',
                          style: TextStyle(
                              color: MyColours.color_ffffff,
                              fontSize: ScreenUtil().setSp(22))),
                    ],
                  ),
                  HEmptyView(20),
                  widget.showBtn
                      ? RoundButton(
                          width: ScreenUtil().setWidth(100),
                          height: ScreenUtil().setWidth(50),
                          radius: ScreenUtil().setWidth(10),
                          text: notSelect ? '停用' : '启用',
                          textColor: MyColours.color_666666,
                          gradientStart: Colors.white,
                          gradientEnd: Colors.white,
                          onPressed: widget.onPressedSwich,
                        )
                      : Container()
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}