pickGridValue<T> method

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

Implementation

Future<T?> pickGridValue<T>(
  List<T> items, {
  T? selected,
  Widget Function(T)? onItemView,
  Widget? Function(T)? onTitle,
  Widget? Function(T)? onHeader,
  Widget? Function(T)? onFooter,
  int columnCount = 0,
  double itemWidth = 80,
  double? itemHeight,
  double aspectRatio = 1.0,
  double verticalSpacing = 0.0,
  double horizontalSpacing = 0.0,
  EdgeInsets? padding,
  String? title,
  bool ok = false,
  bool cancel = false,
  List<Widget>? aboveWidgets,
  List<Widget>? belowWidgets,
}) async {
  return showColumn(
    isContentScrollable: true,
    title: title,
    cancel: cancel,
    ok: ok,
    aboveWidgets: aboveWidgets,
    belowWidgets: belowWidgets,
    padding: EdgeInsets.all(0),
    onContent: (uc) {
      if (!uc.hasResult) {
        uc.setResult(selected);
      }
      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) {
            cell = onItemView(item);
          } else {
            bool checked = uc.getResult() == item;
            cell = GridTile(
              header: onHeader?.call(item),
              footer: onFooter?.call(item),
              child: onTitle?.call(item) ?? item.toString().text(style: uc.themeData.textTheme.titleMedium).centered(),
            );
            if (checked) {
              cell = cell.coloredBox(GRID_SELECTED_BACKGROUND).clipRoundRect(3);
            }
          }
          return cell.inkWell(
            onTap: () {
              uc.setResult(item);
              if (ok) {
                uc.updateState();
              } else {
                uc.pop(item);
              }
            },
          );
        },
      );
    },
  );
}