coupon_item.dart 4.7 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;
  CouponItem({Key key, this.index, this.onPressed, this.couponProvider})
      : 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 Padding(
        padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
        child: Container(
          height: ScreenUtil().setWidth(300),
          padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
          decoration: BoxDecoration(
              color: switchState ? MyColours.app_main : MyColours.color_E0E0E0,
              borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10))),
          child: Stack(
            children: [
              Column(
                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(
                        '说明:大家发哈接电话发费哈咖啡的哈快递费哈就快递费哈加客服哈艰苦奋斗哈佛等哈快回复解答快回复',
                        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: 0,
                right: 0,
                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),
                    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,
                    )
                  ],
                ),
              )
            ],
          ),
        ));
  }
}