FMultiSelect<T>.search constructor
FMultiSelect<T>.search (
- Map<
String, T> items, { - FutureOr<
Iterable< filter()?,T> > - FSelectSearchFieldProperties searchFieldProperties = const FSelectSearchFieldProperties(),
- Widget contentLoadingBuilder() = FMultiSelect.defaultContentLoadingBuilder,
- Widget contentErrorBuilder()?,
- FMultiSelectController<
T> ? controller, - 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>
- Set<
- AutovalidateMode autovalidateMode = AutovalidateMode.onUnfocus,
- String? forceErrorText,
- String? validator(
- Set<
T>
- Set<
- Widget errorBuilder() = FFormFieldProperties.defaultErrorBuilder,
- 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() = FPortalShift.flip,
- Offset offset = Offset.zero,
- FPopoverHideRegion hideRegion = FPopoverHideRegion.excludeChild,
- Widget 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,
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)? filter,
FSelectSearchFieldProperties searchFieldProperties = const FSelectSearchFieldProperties(),
Widget Function(BuildContext, FSelectSearchStyle) contentLoadingBuilder = FMultiSelect.defaultContentLoadingBuilder,
Widget Function(BuildContext, Object?, StackTrace)? contentErrorBuilder,
FMultiSelectController<T>? controller,
FMultiSelectStyle Function(FMultiSelectStyle)? 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>)? onSaved,
AutovalidateMode autovalidateMode = AutovalidateMode.onUnfocus,
String? forceErrorText,
String? Function(Set<T>) validator = _defaultValidator,
Widget Function(BuildContext, String) 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, FPortalChildBox, FPortalBox) shift = FPortalShift.flip,
Offset offset = Offset.zero,
FPopoverHideRegion hideRegion = FPopoverHideRegion.excludeChild,
Widget Function(BuildContext, FMultiSelectStyle) 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,
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,
);
}