pickGridValueSet<T> method

Future<Set<T>?> pickGridValueSet<T>(
  1. List<T> items, {
  2. Iterable<T>? selected,
  3. String? title,
  4. Widget onItemView(
    1. T,
    2. Set<T>
    )?,
  5. Widget? onTitle(
    1. T
    )?,
  6. Widget? onHeader(
    1. T
    )?,
  7. Widget? onFooter(
    1. T
    )?,
  8. List<Widget>? aboveWidgets,
  9. List<Widget>? belowWidgets,
  10. int columnCount = 0,
  11. double itemWidth = 80,
  12. double? itemHeight,
  13. double aspectRatio = 1.0,
  14. double verticalSpacing = 0.0,
  15. double horizontalSpacing = 0.0,
  16. EdgeInsets? padding,
})

Implementation

Future<Set<T>?> pickGridValueSet<T>(
  List<T> items, {
  Iterable<T>? selected,
  String? title,
  Widget Function(T, Set<T>)? onItemView,
  Widget? Function(T)? onTitle,
  Widget? Function(T)? onHeader,
  Widget? Function(T)? onFooter,
  List<Widget>? aboveWidgets,
  List<Widget>? belowWidgets,
  int columnCount = 0,
  double itemWidth = 80,
  double? itemHeight,
  double aspectRatio = 1.0,
  double verticalSpacing = 0.0,
  double horizontalSpacing = 0.0,
  EdgeInsets? padding,
}) async {
  Set<T> resultSet = {};
  if (selected != null) resultSet.addAll(selected);
  return showColumn(
    isContentScrollable: true,
    title: title,
    cancel: true,
    ok: true,
    aboveWidgets: aboveWidgets,
    belowWidgets: belowWidgets,
    padding: EdgeInsets.all(0),
    onContent: (uc) {
      bool isCheck(T item) {
        Set<T> ls = uc.getResult() ?? {};
        return ls.contains(item);
      }

      void toggole(T item) {
        Set<T> ls = uc.getResult() ?? {};
        if (ls.contains(item)) {
          ls.remove(item);
        } else {
          ls.add(item);
        }
      }

      if (!uc.hasResult) uc.setResult(resultSet);
      return XGridView(
        columnCount: columnCount,
        crossAxisExtent: itemWidth,
        mainAxisExtent: itemHeight,
        childAspectRatio: aspectRatio,
        mainAxisSpacing: verticalSpacing,
        crossAxisSpacing: horizontalSpacing,
        padding: padding,
        shrinkWrap: true,
        items: items,
        itemView: (iic) {
          T item = iic.item;
          Widget cell;
          if (onItemView != null) {
            Set<T> ls = uc.getResult() ?? {};
            cell = onItemView(item, ls);
          } else {
            cell = GridTile(
              header: onHeader?.call(item),
              footer: onFooter?.call(item),
              child: onTitle?.call(item) ?? item.toString().text(style: uc.themeData.textTheme.titleMedium).centered(),
            );
            if (isCheck(item)) {
              cell = cell.coloredBox(GRID_SELECTED_BACKGROUND).clipRoundRect(3);
            }
          }
          return cell.inkWell(
            onTap: () {
              toggole(item);
              uc.updateState();
            },
          );
        },
      );
    },
  );
}