table_manage_item.dart 4.96 KB

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/notebook.dart';
import 'package:one_key/res/colors.dart';

import 'package:one_key/models/table.dart' as t;
import 'package:one_key/widgets/v_empty_view.dart';

class ManageTableItem extends StatefulWidget {
  final t.Table table;
  final bool canMulSelected; //是否多选
  final ValueChanged<t.Table>? onSelected;

  final int height; //高度

  ManageTableItem(
    this.table, {
    this.onSelected,
    this.canMulSelected = false,
    this.height = 185,
  });

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

class ManageTableItemState extends State<ManageTableItem> {
  @override
  Widget build(BuildContext context) {
    t.Table table = widget.table;
    return GestureDetector(
      onTap: () {
        widget.onSelected!(table);
      },
      child: Stack(
        children: <Widget>[
          Container(
            decoration: BoxDecoration(
                color: table.selected!
                    ? MyColours.color_199095
                    : MyColours.color_ffffff,
                border: Border.all(
                    width: ScreenUtil().setWidth(2),
                    color: MyColours.color_438E93),
                borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(10)))),
            child: Stack(
              // alignment: Alignment.center,
              children: <Widget>[
                Container(
                  child: Column(
                    // mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      VEmptyView(10),
                      Container(
                          // color: Colors.red,
                          height: ScreenUtil().setWidth(48),
                          alignment: Alignment.center,
                          child: Text(
                            table.name!,
                            maxLines: 1,
                            style: TextStyle(
                                color: table.selected!
                                    ? MyColours.color_ffffff
                                    : MyColours.color_438E93,
                                fontSize: ScreenUtil().setSp(32),
                                decoration: TextDecoration.none,
                                fontWeight: FontWeight.bold),
                            overflow: TextOverflow.ellipsis,
                          )),
                      table.tableNum != '' && table.tableNum != null
                          ? Container(
                              // color: Colors.red,
                              alignment: Alignment.center,
                              height: ScreenUtil().setWidth(48),

                              child: Text(
                                table.tableNum,
                                style: TextStyle(
                                    color: table.selected!
                                        ? MyColours.color_ffffff
                                        : MyColours.color_000000,
                                    fontSize: ScreenUtil().setSp(14),
                                    decoration: TextDecoration.none,
                                    fontWeight: FontWeight.normal),
                                overflow: TextOverflow.ellipsis,
                              ),
                            )
                          : SizedBox()
                    ],
                  ),
                ),
                Positioned(
                  left: 0,
                  top: 0,
                  child: table.tidStr == null
                      ? Container()
                      : Container(
                          width: ScreenUtil().setWidth(44),
                          height: ScreenUtil().setWidth(22),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: table.selected!
                                  ? MyColours.color_199095
                                  : MyColours.color_999999,
                              borderRadius: BorderRadius.only(
                                topLeft:
                                    Radius.circular(ScreenUtil().setWidth(8)),
                              )),
                          child: Text(table.tidStr,
                              style: TextStyle(
                                  color: MyColours.color_ffffff,
                                  fontSize: ScreenUtil().setSp(14),
                                  decoration: TextDecoration.none,
                                  fontWeight: FontWeight.normal)),
                        ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}