showPickerBottomSheet<T, V> function
Future<T?>
showPickerBottomSheet<T, V>(
- BuildContext context, {
- required List<
T> sources, - required ValueMapper<
T, String?> labelMapper, - String? title,
- T? initialData,
- V? initialValue,
- ValueMapper<
T, V> ? valueMapper, - ValueMapper<
T, String> ? subtitleMapper, - bool enabledMapper(
- int index,
- T item
- ValueMapper<
T, bool> ? inputEnabledMapper, - ValueMapper<
T, bool> ? dataMapper, - PickerItemBuilder<
T> ? pickerItemBuilder, - bool? isScrollControlled,
- bool? showSearchField,
单选选择
Implementation
Future<T?> showPickerBottomSheet<T, V>(
BuildContext context, {
required List<T> sources,
required ValueMapper<T, String?> labelMapper,
String? title,
T? initialData,
V? initialValue,
ValueMapper<T, V>? valueMapper,
ValueMapper<T, String>? subtitleMapper,
bool Function(int index, T item)? enabledMapper,
ValueMapper<T, bool>? inputEnabledMapper,
ValueMapper<T, bool>? dataMapper,
PickerItemBuilder<T>? pickerItemBuilder,
bool? isScrollControlled,
bool? showSearchField,
}) async {
valueMapper ??= labelMapper as ValueMapper<T, V>;
isScrollControlled ??= sources.length > 10;
T? data = initialData ??
(initialValue == null
? null
: sources.firstWhere((e) => valueMapper!(e) == initialValue));
final Widget content = _PickerContent<T>(
labelMapper: labelMapper,
sources: sources,
onChanged: (val) => data = val,
subtitleMapper: subtitleMapper,
pickerItemBuilder: pickerItemBuilder,
initialData: data,
enabledMapper: enabledMapper,
dataMapper: dataMapper,
inputEnabledMapper: inputEnabledMapper,
);
return await showDefaultBottomSheet<T>(
context,
title: title ?? TxLocalizations.of(context).pickerTitle,
contentBuilder: (context) => content,
onConfirm: () => Navigator.pop(context, data),
isScrollControlled: isScrollControlled,
);
}