showPickerBottomSheet<T, V> function

Future<T?> showPickerBottomSheet<T, V>(
  1. BuildContext context, {
  2. required List<T> source,
  3. required ValueMapper<T, String?> labelMapper,
  4. String? title,
  5. T? initialData,
  6. V? initialValue,
  7. ValueMapper<T, V?>? valueMapper,
  8. DataWidgetBuilder<T>? subtitleBuilder,
  9. ValueMapper<T, bool>? disabledWhen,
  10. PickerItemBuilder<T>? itemBuilder,
  11. bool? isScrollControlled,
  12. bool? showSearchField,
  13. Widget? placeholder,
  14. 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,
  );
}