coupon_item.dart 4.72 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/res/colors.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 int index;
  final VoidCallback onPressed;
  final CouponProvider couponProvider;
  final bool showBtn;
  CouponItem(
      {Key key,
      this.index,
      this.onPressed,
      this.couponProvider,
      this.showBtn = false})
      : super(key: key);

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

class _CouponItemState extends State<CouponItem> {
  @override
  Widget build(BuildContext context) {
    bool switchState = widget.couponProvider.swichStateData[widget.index];
    return Stack(
      children: [
        Container(
          // width: ScreenUtil().setWidth(610),
          margin: EdgeInsets.symmetric(
              horizontal: ScreenUtil().setWidth(30),
              vertical: ScreenUtil().setWidth(12)),
          padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
          decoration: BoxDecoration(
              color: switchState ? MyColours.app_main : MyColours.color_E0E0E0,
              borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10))),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Text(
                    '九折券',
                    style: TextStyle(
                        color: MyColours.color_ffffff,
                        fontSize: ScreenUtil().setSp(50),
                        fontWeight: FontWeight.bold),
                  ),
                  Text('(无门槛)',
                      style: TextStyle(
                          color: MyColours.color_ffffff,
                          fontSize: ScreenUtil().setSp(22),
                          fontWeight: FontWeight.bold))
                ],
              ),
              VEmptyView(20),
              Container(
                padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
                child: Text('说明:大哈就快费复大家发哈接电话费哈就快递费快回复解答快回复',
                    maxLines: 30,
                    overflow: TextOverflow.ellipsis,
                    softWrap: false,
                    style: TextStyle(
                        color: switchState
                            ? MyColours.app_main
                            : MyColours.color_e5e5e5,
                        fontSize: ScreenUtil().setSp(22))),
                decoration: BoxDecoration(
                    color: MyColours.color_ffffff,
                    borderRadius:
                        BorderRadius.circular(ScreenUtil().setWidth(10))),
              ),
              Container(
                padding: EdgeInsets.only(top: ScreenUtil().setWidth(20)),
                child: Text('有效期:2021.01.01 00:00:00 至 2021.01.31 23:59:59',
                    style: TextStyle(
                        color: MyColours.color_ffffff,
                        fontSize: ScreenUtil().setSp(22))),
              ),
            ],
          ),
        ),
        Positioned(
          top: ScreenUtil().setWidth(40),
          right: ScreenUtil().setWidth(40),
          child: Row(
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('被领取:99张',
                      style: TextStyle(
                          color: MyColours.color_ffffff,
                          fontSize: ScreenUtil().setSp(22))),
                  Text('已使用:9张',
                      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: switchState ? '停用' : '启用',
                      textColor: MyColours.color_666666,
                      gradientStart: Colors.white,
                      gradientEnd: Colors.white,
                      onPressed: widget.onPressed,
                    )
                  : Container()
            ],
          ),
        )
      ],
    );
  }
}