showPickerBottomSheet<T, V> function
Future<T?>
showPickerBottomSheet<T, V>(
- BuildContext context, {
- required List<
T> source, - required ValueMapper<
T, String?> labelMapper, - String? title,
- T? initialData,
- V? initialValue,
- ValueMapper<
T, V?> ? valueMapper, - DataWidgetBuilder<
T> ? subtitleBuilder, - ValueMapper<
T, bool> ? disabledWhen, - PickerItemBuilder<
T> ? itemBuilder, - bool? isScrollControlled,
- bool? showSearchField,
- Widget? placeholder,
- ListTileThemeData? listTileTheme,
单选选择
Implementation
Future<T?> showPickerBottomSheet<T, V>(
BuildContext context, {
required List<T> source,
required ValueMapper<T, String?> labelMapper,
String? title,
T? initialData,
V? initialValue,
ValueMapper<T, V?>? valueMapper,
DataWidgetBuilder<T>? subtitleBuilder,
ValueMapper<T, bool>? disabledWhen,
PickerItemBuilder<T>? itemBuilder,
bool? isScrollControlled,
bool? showSearchField,
Widget? placeholder,
ListTileThemeData? listTileTheme,
}) async {
valueMapper ??= (T data) => data as V;
isScrollControlled ??= source.length > 10;
T? data = initialData ??
(initialValue == null
? null
: source.firstWhere((e) => valueMapper!(e) == initialValue));
final Widget content = TxPicker<T, V>(
labelMapper: labelMapper,
source: source,
onChanged: (val) => data = val,
valueMapper: valueMapper,
subtitleBuilder: subtitleBuilder,
itemBuilder: itemBuilder,
initialData: data,
disabledWhen: disabledWhen,
showSearchField: showSearchField,
placeholder: placeholder,
listTileTheme: listTileTheme,
);
return await showDefaultBottomSheet<T>(
context,
title: title ?? TxLocalizations.of(context).pickerTitle,
contentBuilder: (context) => content,
onConfirm: () => Navigator.pop(context, data),
isScrollControlled: isScrollControlled,
);
}