showMultiPickerBottomSheet<T, V> function
Future<List<V> ?>
showMultiPickerBottomSheet<T, V>(
- BuildContext context, {
- required List<
T> sources, - required ValueMapper<
T, String?> labelMapper, - String? title,
- List<
V> ? initialValue, - ValueMapper<
T, V> ? valueMapper, - ValueMapper<
T, String> ? subtitleMapper, - MultiPickerItemBuilder<
T> ? pickerItemBuilder, - bool? isScrollControlled,
- int? maxCount,
- int? minCount,
- ValueMapper<
T, bool> ? editableMapper, - ValueMapper<
String, T> ? editableItemMapper, - LabelEditCallback? onLabelChanged,
- bool enabledMapper(
- int index,
- T data
多选选择
点击取消将返回 null,开发者可根据返回值是否为 null 判断用户是否取消选择。
Implementation
Future<List<V>?> showMultiPickerBottomSheet<T, V>(
BuildContext context, {
required List<T> sources,
required ValueMapper<T, String?> labelMapper,
String? title,
List<V>? initialValue,
ValueMapper<T, V>? valueMapper,
ValueMapper<T, String>? subtitleMapper,
MultiPickerItemBuilder<T>? pickerItemBuilder,
bool? isScrollControlled,
int? maxCount,
int? minCount,
ValueMapper<T, bool>? editableMapper,
ValueMapper<String, T>? editableItemMapper,
LabelEditCallback? onLabelChanged,
bool Function(int index, T data)? enabledMapper,
}) async {
valueMapper ??= (T data) => data as V;
isScrollControlled ??= sources.length > 10;
List<V> data = [...?initialValue];
final Widget content = _MultiSelectContent<T, V>(
valueMapper: valueMapper,
labelMapper: labelMapper,
sources: sources,
onChanged: (val) => data = val,
subtitleMapper: subtitleMapper,
pickerItemBuilder: pickerItemBuilder,
editableMapper: editableMapper,
editableItemMapper: editableItemMapper,
onLabelChanged: onLabelChanged,
initialData: data,
maxCount: maxCount,
enabledMapper: enabledMapper,
);
return await showDefaultBottomSheet<List<V>>(
context,
title: title ?? TxLocalizations.of(context).pickerTitle,
contentBuilder: (context) => content,
onConfirm: () => Navigator.pop(context, data),
isScrollControlled: isScrollControlled,
);
}