pickGridValue<T> method
Future<T?>
pickGridValue<T>(
- List<
T> items, { - T? selected,
- Widget onItemView(
- T
- Widget? onTitle(
- T
- Widget? onHeader(
- T
- 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,
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);
}
},
);
},
);
},
);
}