area_item_table.dart 3.59 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/area.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/widgets/h_empty_view.dart';

class AreaItemTable extends StatefulWidget {
  final String currentArea; //当前选中区域名称
  final Area area;
  final ValueChanged selectCallback;

  AreaItemTable(this.area, this.currentArea, this.selectCallback);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new AreaItemTableState();
  }
}

class AreaItemTableState extends State<AreaItemTable> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    Area area = widget.area;
    bool isSelected = area.name == widget.currentArea;
    return GestureDetector(
      onTap: () {
        if (widget.selectCallback != null) {
          widget.selectCallback(widget.area);
        }
      },
      child: Stack(
        overflow: Overflow.visible,
        alignment: Alignment.topLeft,
        children: <Widget>[
          Container(
            width: ScreenUtil().setWidth(104 * 2),
            height: ScreenUtil().setWidth(80),
            margin: EdgeInsets.only(
              right: ScreenUtil().setWidth(20),
              top: ScreenUtil().setWidth(20),
            ),
            padding: EdgeInsets.symmetric(
                horizontal: ScreenUtil().setWidth(20),
                vertical: ScreenUtil().setWidth(10)),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
                color: isSelected
                    ? MyColours.color_199095
                    : MyColours.color_ffffff,
                border: Border.all(
                    color: MyColours.color_199095,
                    width: ScreenUtil().setWidth(2))),
            child: Text(
              area.name,
              style: TextStyle(
                  color: isSelected
                      ? MyColours.color_ffffff
                      : MyColours.color_199095,
                  fontSize: ScreenUtil().setSp(28),
                  decoration: TextDecoration.none,
                  fontWeight: FontWeight.normal),
            ),
          ),
          area.count == -1
              ? Container()
              : Positioned(
                  left: 0,
                  top: 0,
                  child: Container(
                    width: ScreenUtil().setWidth(78),
                    height: ScreenUtil().setWidth(30),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: area.count <= 0
                            ? MyColours.color_999999
                            : MyColours.color_63a6d1,
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(ScreenUtil().setWidth(10)),
                            topRight:
                                Radius.circular(ScreenUtil().setWidth(15)),
                            bottomRight:
                                Radius.circular(ScreenUtil().setWidth(15)))),
                    child: Text(area.count == 0 ? "满座" : "余${area.count}",
                        style: TextStyle(
                            color: MyColours.color_ffffff,
                            fontSize: ScreenUtil().setSp(26),
                            decoration: TextDecoration.none,
                            fontWeight: FontWeight.normal)),
                  ),
                ),
        ],
      ),
    );
  }
}