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