pickValueSet<T> method
Future<Set<T>?>
pickValueSet<
T>( - List<T> items, {
- Iterable<T>? selected,
- String? title,
- Widget onItemView(
- T,
- Set<T>
)?,
- Widget? onTitle(
- T
)?,
- Widget? onSubtitle(
- T
)?,
- Widget? onLeading(
- T
)?,
- Widget? onTrailing(
- T
)?,
- List<Widget>? aboveWidgets,
- List<Widget>? belowWidgets,
- EdgeInsets? padding,
- bool separated = true,
})
Implementation
Future<Set<T>?> pickValueSet<T>(
List<T> items, {
Iterable<T>? selected,
String? title,
Widget Function(T, Set<T>)? onItemView,
Widget? Function(T)? onTitle,
Widget? Function(T)? onSubtitle,
Widget? Function(T)? onLeading,
Widget? Function(T)? onTrailing,
List<Widget>? aboveWidgets,
List<Widget>? belowWidgets,
EdgeInsets? padding,
bool separated = true,
}) 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 XListView(
items: items,
shrinkWrap: true,
padding: padding,
separator: separated,
itemView: (cii) {
var item = cii.item;
if (onItemView != null) {
Set<T> ls = uc.getResult() ?? {};
return onItemView(item, ls);
}
return ListTile(
title: onTitle?.call(item) ?? item.toString().titleMedium(),
subtitle: onSubtitle?.call(item),
leading: onLeading?.call(item),
trailing: onTrailing?.call(item) ?? (isCheck(item) ? Icons.check.icon() : null),
onTap: () {
toggole(item);
uc.updateState();
},
);
},
);
},
);
}