FMultiSelect<T> constructor

FMultiSelect<T>({
  1. required Map<String, T> items,
  2. FMultiValueControl<T>? control,
  3. FPopoverControl popoverControl = const .managed(),
  4. FMultiSelectStyle style(
    1. FMultiSelectStyle style
    )?,
  5. bool autofocus = false,
  6. FocusNode? focusNode,
  7. FFieldIconBuilder<FMultiSelectStyle>? prefixBuilder,
  8. FFieldIconBuilder<FMultiSelectStyle>? suffixBuilder = defaultIconBuilder,
  9. Widget? label,
  10. Widget? description,
  11. bool enabled = true,
  12. void onSaved(
    1. Set<T> values
    )?,
  13. VoidCallback? onReset,
  14. AutovalidateMode autovalidateMode = .onUnfocus,
  15. String? forceErrorText,
  16. String? validator(
    1. Set<T> values
    ) = _defaultValidator,
  17. Widget errorBuilder(
    1. BuildContext context,
    2. String message
    ) = FFormFieldProperties.defaultErrorBuilder,
  18. Widget? hint,
  19. bool keepHint = true,
  20. int sort(
    1. T a,
    2. T b
    )?,
  21. Widget tagBuilder(
    1. BuildContext context,
    2. FMultiValueNotifier<T> controller,
    3. FMultiSelectStyle style,
    4. T value,
    5. Widget label,
    )?,
  22. TextAlign textAlign = .start,
  23. TextDirection? textDirection,
  24. bool clearable = false,
  25. AlignmentGeometry contentAnchor = AlignmentDirectional.topStart,
  26. AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart,
  27. FPortalConstraints contentConstraints = const FAutoWidthPortalConstraints(maxHeight: 300),
  28. FPortalSpacing contentSpacing = const .spacing(4),
  29. FPortalOverflow contentOverflow = .flip,
  30. Offset contentOffset = Offset.zero,
  31. FPopoverHideRegion contentHideRegion = .excludeChild,
  32. Object? contentGroupId,
  33. Widget contentEmptyBuilder(
    1. BuildContext context,
    2. FMultiSelectStyle style
    ) = FMultiSelect.defaultContentEmptyBuilder,
  34. ScrollController? contentScrollController,
  35. bool contentScrollHandles = false,
  36. ScrollPhysics contentPhysics = const ClampingScrollPhysics(),
  37. FItemDivider contentDivider = .none,
  38. Key? key,
})

Creates a FMultiSelect from the given items.

For more control over the appearance of items, use FMultiSelect.rich.

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({
  required Map<String, T> items,
  FMultiValueControl<T>? control,
  FPopoverControl popoverControl = const .managed(),
  FMultiSelectStyle Function(FMultiSelectStyle style)? style,
  bool autofocus = false,
  FocusNode? focusNode,
  FFieldIconBuilder<FMultiSelectStyle>? prefixBuilder,
  FFieldIconBuilder<FMultiSelectStyle>? suffixBuilder = defaultIconBuilder,
  Widget? label,
  Widget? description,
  bool enabled = true,
  void Function(Set<T> values)? onSaved,
  VoidCallback? onReset,
  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 a, T b)? sort,
  Widget Function(
    BuildContext context,
    FMultiValueNotifier<T> controller,
    FMultiSelectStyle style,
    T value,
    Widget label,
  )?
  tagBuilder,
  TextAlign textAlign = .start,
  TextDirection? textDirection,
  bool clearable = false,
  AlignmentGeometry contentAnchor = AlignmentDirectional.topStart,
  AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart,
  FPortalConstraints contentConstraints = const FAutoWidthPortalConstraints(maxHeight: 300),
  FPortalSpacing contentSpacing = const .spacing(4),
  FPortalOverflow contentOverflow = .flip,
  Offset contentOffset = Offset.zero,
  FPopoverHideRegion contentHideRegion = .excludeChild,
  Object? contentGroupId,
  Widget Function(BuildContext context, FMultiSelectStyle style) contentEmptyBuilder =
      FMultiSelect.defaultContentEmptyBuilder,
  ScrollController? contentScrollController,
  bool contentScrollHandles = false,
  ScrollPhysics contentPhysics = const ClampingScrollPhysics(),
  FItemDivider contentDivider = .none,
  Key? key,
}) {
  final inverse = {for (final MapEntry(:key, :value) in items.entries) value: key};
  return .rich(
    control: control,
    popoverControl: popoverControl,
    style: style,
    autofocus: autofocus,
    focusNode: focusNode,
    prefixBuilder: prefixBuilder,
    suffixBuilder: suffixBuilder,
    label: label,
    description: description,
    format: (value) => Text(inverse[value] ?? ''),
    sort: sort,
    tagBuilder: tagBuilder,
    enabled: enabled,
    onSaved: onSaved,
    onReset: onReset,
    autovalidateMode: autovalidateMode,
    forceErrorText: forceErrorText,
    validator: validator,
    errorBuilder: errorBuilder,
    hint: hint,
    keepHint: keepHint,
    textAlign: textAlign,
    textDirection: textDirection,
    clearable: clearable,
    contentAnchor: contentAnchor,
    fieldAnchor: fieldAnchor,
    contentConstraints: contentConstraints,
    contentSpacing: contentSpacing,
    contentOverflow: contentOverflow,
    contentOffset: contentOffset,
    contentHideRegion: contentHideRegion,
    contentGroupId: contentGroupId,
    contentEmptyBuilder: contentEmptyBuilder,
    contentScrollController: contentScrollController,
    contentScrollHandles: contentScrollHandles,
    contentPhysics: contentPhysics,
    contentDivider: contentDivider,
    key: key,
    children: [for (final MapEntry(:key, :value) in items.entries) .item(title: Text(key), value: value)],
  );
}