buildTagSelectCell<T> function

Widget buildTagSelectCell<T>(
  1. BuildContext context,
  2. String tag, {
  3. IconData iconData = Icons.keyboard_arrow_down,
  4. Widget? icon,
  5. Color? iconColor = const Color(0xffbcbcbc),
  6. double tagWidth = 100,
  7. String? hintText,
  8. double fontSize = 16,
  9. double miniHeight = 40,
  10. Color tagColor = const Color(0xff63728f),
  11. TextEditingController? controller,
  12. TextInputType? inputType,
  13. InputDecoration? inputDecoration,
  14. List<T>? items,
  15. BuildCheckChild<T>? buildCheckChild,
  16. bool autoHeight = true,
  17. VoidCallback? onTap,
  18. bool required = false,
  19. bool isEdit = true,
  20. int? valueMaxLines = 1,
  21. double paddingRight = 0.0,
  22. EdgeInsetsGeometry padding = const EdgeInsets.all(1),
  23. bool showLine = false,
  24. Color color = Colors.transparent,
  25. Widget? child,
  26. ValueChanged<int>? onItemSelected,
  27. double iconWidth = 40,
  28. TagCellStyle style = TagCellStyle.style2,
  29. double? dialogWidth,
})

onItemSelected -1 代表无数据

Implementation

Widget buildTagSelectCell<T>(
  BuildContext context,
  String tag, {
  IconData iconData = Icons.keyboard_arrow_down,
  Widget? icon,
  Color? iconColor = const Color(0xffbcbcbc),
  double tagWidth = 100,
  String? hintText,
  double fontSize = 16,
  double miniHeight = 40,
  Color tagColor = const Color(0xff63728f),
  TextEditingController? controller,
  TextInputType? inputType,
  InputDecoration? inputDecoration,
  List<T>? items,
  BuildCheckChild<T>? buildCheckChild,
  bool autoHeight = true,
  VoidCallback? onTap,
  bool required = false,
  bool isEdit = true,
  int? valueMaxLines = 1,
  double paddingRight = 0.0,
  EdgeInsetsGeometry padding = const EdgeInsets.all(1),
  bool showLine = false,
  Color color = Colors.transparent,
  Widget? child,
  ValueChanged<int>? onItemSelected,
  double iconWidth = 40,
  TagCellStyle style = TagCellStyle.style2,
  double? dialogWidth,
}) {
  return Material(
    color: color,
    child: Ink(
      child: InkWell(
        onTap: isEdit
            ? (onItemSelected == null
                ? onTap
                : () {
                    if (items == null || items.isEmpty) {
                      onItemSelected(-1);
                      return;
                    }
                    showBottomPopup(
                      context,
                      '请选择$tag',
                      items,
                      buildCheckChild: buildCheckChild,
                      autoHeight: autoHeight,
                      width: dialogWidth ??
                          ((![TargetPlatform.iOS, TargetPlatform.android]
                                  .contains(defaultTargetPlatform))
                              ? min(MediaQuery.of(context).size.width, 720)
                              : MediaQuery.of(context).size.width),
                    ).then((index) {
                      if (index == null || index < 0) return;
                      onItemSelected(index);
                    });
                  })
            : null,
        child: Column(children: <Widget>[
          Padding(
            padding: padding,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                SizedBox(
                    width: tagWidth,
                    height: miniHeight,
                    child: Row(
                      children: <Widget>[
                        required
                            ? Icon(MdiIcons.multiplication,
                                size: 8, color: Colors.red)
                            : Container(width: 0),
                        const SizedBox(width: 5),
                        Expanded(
                          child: Text(
                            tag,
                            overflow: TextOverflow.ellipsis,
                            maxLines: 1,
                            style: TextStyle(
                                color: tagColor,
                                height: 1.1,
                                fontSize: fontSize),
                          ),
                        ),
                      ],
                    )),
                Expanded(
                  child: child ??
                      TextField(
                        enabled: false,
                        enableInteractiveSelection: false,
                        controller: controller,
                        keyboardType: inputType ?? TextInputType.text,
                        textAlign: style == TagCellStyle.style1
                            ? TextAlign.start
                            : TextAlign.right,
                        maxLines: valueMaxLines,
                        decoration: inputDecoration ??
                            InputDecoration(
                              hintText: hintText ?? '请选择$tag',
                              hintStyle: TextStyle(
                                  fontSize: fontSize,
                                  height: 1.1,
                                  color: const Color(0xffd2d2d2)),
                              border: InputBorder.none,
                              labelStyle: TextStyle(fontSize: fontSize),
                            ),
                        style: TextStyle(
                          height: 1.1,
                          fontSize: fontSize,
                          color: Colors.black,
                        ),
                      ),
                ),
                const SizedBox(width: 5),
                Container(
                  width: isEdit ? iconWidth : 0,
                  alignment: Alignment.topRight,
                  child: isEdit
                      ? (icon ??
                          Icon(iconData,
                              color: iconColor ?? const Color(0xffbcbcbc)))
                      : Container(),
                ),
                SizedBox(width: paddingRight)
              ],
            ),
          ),
          showLine ? Divider(height: 0.5, color: Colors.grey[50]) : Container(),
        ]),
      ),
    ),
  );
}