pickGridValue<T> static 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. DialogWidth? dialogWidth,
  18. List<Widget>? aboveWidgets,
  19. List<Widget>? belowWidgets,
  20. Alignment? dialogAlignment,
  21. EdgeInsets? dialogInsets,
})

Implementation

static 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,
  DialogWidth? dialogWidth,
  List<Widget>? aboveWidgets,
  List<Widget>? belowWidgets,
  Alignment? dialogAlignment,
  EdgeInsets? dialogInsets,
}) async {
  return await showDialogX((b) {
    b.init(result: selected);
    return b.buildGrid(
      items,
      columnCount: columnCount,
      itemWidth: itemWidth,
      itemHeight: itemHeight,
      aspectRatio: aspectRatio,
      verticalSpacing: verticalSpacing,
      horizontalSpacing: horizontalSpacing,
      padding: padding,
      builder: (iic) {
        T item = iic.item;
        Widget cell;
        if (onItemView != null) {
          cell = onItemView(item);
        } else {
          bool checked = b.result == item;
          cell = GridTile(
            header: onHeader?.call(item),
            footer: onFooter?.call(item),
            child: onTitle?.call(item) ?? item.toString().text(style: b.context.themeData.textTheme.titleMedium).centered(),
          ).let((e) {
            if (!checked) return e;
            return e.coloredBox(b.gridSelectedBackground).clipRoundRect(3);
          });
        }
        return cell.inkWell(onTap: () {
          b.setResult(item);
          if (ok == true) {
            b.updateState();
          } else {
            b.clickOK();
          }
        });
      },
      title: title,
      ok: ok,
      cancel: cancel,
      dialogWidth: dialogWidth,
      aboveWidgets: aboveWidgets,
      belowWidgets: belowWidgets,
    );
  }, alignment: dialogAlignment, insetPadding: dialogInsets);
}