FMultiSelect<T>.search constructor
FMultiSelect<T>.search (
- Map<
String, T> items, { - FutureOr<
Iterable< filter(T> >- String query
- FSelectSearchFieldProperties searchFieldProperties = const FSelectSearchFieldProperties(),
- Widget contentLoadingBuilder(
- BuildContext context,
- FSelectSearchStyle style
- Widget contentErrorBuilder(
- BuildContext context,
- Object? error,
- StackTrace stackTrace
- FMultiSelectController<
T> ? controller, - FMultiSelectStyle style(
- FMultiSelectStyle style
- bool autofocus = false,
- FocusNode? focusNode,
- FFieldIconBuilder<
FMultiSelectStyle> ? prefixBuilder, - FFieldIconBuilder<
FMultiSelectStyle> ? suffixBuilder = defaultIconBuilder, - Widget? label,
- Widget? description,
- bool enabled = true,
- ValueChanged<
Set< ? onChange,T> > - void onSaved(
- Set<
T> values
- Set<
- VoidCallback? onReset,
- AutovalidateMode autovalidateMode = AutovalidateMode.onUnfocus,
- String? forceErrorText,
- String? validator(
- Set<
T> values
- Set<
- Widget errorBuilder(
- BuildContext context,
- String message
- Widget? hint,
- bool keepHint = true,
- int sort(
- T,
- T
- FMultiSelectTagBuilder<
T> ? tagBuilder, - TextAlign textAlign = TextAlign.start,
- TextDirection? textDirection,
- bool clearable = false,
- AlignmentGeometry anchor = AlignmentDirectional.topStart,
- AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart,
- FPortalConstraints popoverConstraints = const FAutoWidthPortalConstraints(maxHeight: 300),
- FPortalSpacing spacing = const FPortalSpacing(4),
- Offset shift(
- Size size,
- FPortalChildBox childBox,
- FPortalBox portalBox
- Offset offset = Offset.zero,
- FPopoverHideRegion hideRegion = FPopoverHideRegion.excludeChild,
- Widget contentEmptyBuilder(
- BuildContext context,
- FMultiSelectStyle style
- ScrollController? contentScrollController,
- bool contentScrollHandles = false,
- ScrollPhysics contentPhysics = const ClampingScrollPhysics(),
- FItemDivider contentDivider = FItemDivider.none,
- int min = 0,
- int? max,
- Set<
T> ? initialValue, - Key? key,
Creates a searchable select with dynamic content based on the given items
and search input.
The searchFieldProperties
can be used to customize the search field.
The filter
callback produces a list of items based on the search query. Defaults to returning items that start
with the query string.
The contentLoadingBuilder
is used to show a loading indicator while the search results is processed
asynchronously by filter
.
The contentErrorBuilder
is used to show an error message when filter
is asynchronous and fails.
For more control over the appearance of items, use FMultiSelect.searchBuilder.
Contract
Each key in items
must map to a unique value. Having multiple keys map to the same value will result in
undefined behavior.
Implementation
factory FMultiSelect.search(
Map<String, T> items, {
FutureOr<Iterable<T>> Function(String query)? filter,
FSelectSearchFieldProperties searchFieldProperties = const FSelectSearchFieldProperties(),
Widget Function(BuildContext context, FSelectSearchStyle style) contentLoadingBuilder =
FMultiSelect.defaultContentLoadingBuilder,
Widget Function(BuildContext context, Object? error, StackTrace stackTrace)? contentErrorBuilder,
FMultiSelectController<T>? controller,
FMultiSelectStyle Function(FMultiSelectStyle style)? style,
bool autofocus = false,
FocusNode? focusNode,
FFieldIconBuilder<FMultiSelectStyle>? prefixBuilder,
FFieldIconBuilder<FMultiSelectStyle>? suffixBuilder = defaultIconBuilder,
Widget? label,
Widget? description,
bool enabled = true,
ValueChanged<Set<T>>? onChange,
void Function(Set<T> values)? onSaved,
VoidCallback? onReset,
AutovalidateMode autovalidateMode = AutovalidateMode.onUnfocus,
String? forceErrorText,
String? Function(Set<T> values) validator = _defaultValidator,
Widget Function(BuildContext context, String message) errorBuilder = FFormFieldProperties.defaultErrorBuilder,
Widget? hint,
bool keepHint = true,
int Function(T, T)? sort,
FMultiSelectTagBuilder<T>? tagBuilder,
TextAlign textAlign = TextAlign.start,
TextDirection? textDirection,
bool clearable = false,
AlignmentGeometry anchor = AlignmentDirectional.topStart,
AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart,
FPortalConstraints popoverConstraints = const FAutoWidthPortalConstraints(maxHeight: 300),
FPortalSpacing spacing = const FPortalSpacing(4),
Offset Function(Size size, FPortalChildBox childBox, FPortalBox portalBox) shift = FPortalShift.flip,
Offset offset = Offset.zero,
FPopoverHideRegion hideRegion = FPopoverHideRegion.excludeChild,
Widget Function(BuildContext context, FMultiSelectStyle style) contentEmptyBuilder = defaultContentEmptyBuilder,
ScrollController? contentScrollController,
bool contentScrollHandles = false,
ScrollPhysics contentPhysics = const ClampingScrollPhysics(),
FItemDivider contentDivider = FItemDivider.none,
int min = 0,
int? max,
Set<T>? initialValue,
Key? key,
}) {
final inverse = {for (final MapEntry(:key, :value) in items.entries) value: key};
return FMultiSelect<T>.searchBuilder(
format: (value) => Text(inverse[value] ?? ''),
filter:
filter ??
(query) => items.entries
.where((entry) => entry.key.toLowerCase().startsWith(query.toLowerCase()))
.map((entry) => entry.value)
.toList(),
contentBuilder: (context, _, values) => [
for (final value in values) FSelectItem<T>(title: Text(inverse[value]!), value: value),
],
searchFieldProperties: searchFieldProperties,
contentLoadingBuilder: contentLoadingBuilder,
contentErrorBuilder: contentErrorBuilder,
controller: controller,
style: style,
autofocus: autofocus,
focusNode: focusNode,
prefixBuilder: prefixBuilder,
suffixBuilder: suffixBuilder,
label: label,
description: description,
enabled: enabled,
onChange: onChange,
onSaved: onSaved,
onReset: onReset,
autovalidateMode: autovalidateMode,
forceErrorText: forceErrorText,
validator: validator,
errorBuilder: errorBuilder,
hint: hint,
keepHint: keepHint,
sort: sort,
tagBuilder: tagBuilder,
textAlign: textAlign,
textDirection: textDirection,
clearable: clearable,
anchor: anchor,
fieldAnchor: fieldAnchor,
popoverConstraints: popoverConstraints,
spacing: spacing,
shift: shift,
offset: offset,
hideRegion: hideRegion,
contentEmptyBuilder: contentEmptyBuilder,
contentScrollController: contentScrollController,
contentScrollHandles: contentScrollHandles,
contentPhysics: contentPhysics,
contentDivider: contentDivider,
min: min,
max: max,
initialValue: initialValue,
key: key,
);
}