showPickerBottomSheet<T, V> function

Future<T?> showPickerBottomSheet<T, V>(
  1. BuildContext context, {
  2. required List<T> sources,
  3. required ValueMapper<T, String?> labelMapper,
  4. String? title,
  5. T? initialData,
  6. V? initialValue,
  7. ValueMapper<T, V>? valueMapper,
  8. ValueMapper<T, String>? subtitleMapper,
  9. bool enabledMapper(
    1. int index,
    2. T item
    )?,
  10. ValueMapper<T, bool>? inputEnabledMapper,
  11. ValueMapper<T, bool>? dataMapper,
  12. PickerItemBuilder<T>? pickerItemBuilder,
  13. bool? isScrollControlled,
  14. 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,
  );
}