FSelect<T> constructor

FSelect<T>({
  1. required Map<String, T> items,
  2. FSelectControl<T>? control,
  3. FPopoverControl popoverControl = const .managed(),
  4. FSelectStyle style(
    1. FSelectStyle style
    )?,
  5. bool autofocus = false,
  6. FocusNode? focusNode,
  7. FFieldBuilder<FSelectStyle> builder = _fieldBuilder,
  8. FFieldIconBuilder<FSelectStyle>? prefixBuilder,
  9. FFieldIconBuilder<FSelectStyle>? suffixBuilder = defaultIconBuilder,
  10. Widget? label,
  11. Widget? description,
  12. bool enabled = true,
  13. FormFieldSetter<T>? onSaved,
  14. VoidCallback? onReset,
  15. AutovalidateMode autovalidateMode = .onUnfocus,
  16. String? forceErrorText,
  17. FormFieldValidator<T> validator = _defaultValidator,
  18. Widget errorBuilder(
    1. BuildContext context,
    2. String message
    ) = FFormFieldProperties.defaultErrorBuilder,
  19. String? hint,
  20. TextAlign textAlign = .start,
  21. TextAlignVertical? textAlignVertical,
  22. TextDirection? textDirection,
  23. bool expands = false,
  24. MouseCursor mouseCursor = .defer,
  25. bool canRequestFocus = true,
  26. bool clearable = false,
  27. AlignmentGeometry contentAnchor = AlignmentDirectional.topStart,
  28. AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart,
  29. FPortalConstraints contentConstraints = const FAutoWidthPortalConstraints(maxHeight: 300),
  30. FPortalSpacing contentSpacing = const .spacing(4),
  31. FPortalOverflow contentOverflow = .flip,
  32. Offset contentOffset = .zero,
  33. FPopoverHideRegion contentHideRegion = .excludeChild,
  34. Object? contentGroupId,
  35. bool autoHide = true,
  36. Widget contentEmptyBuilder(
    1. BuildContext context,
    2. FSelectStyle style
    ) = defaultContentEmptyBuilder,
  37. ScrollController? contentScrollController,
  38. @Deprecated('Usage of scroll handles seem to be low while its maintenance burden far outweighs its benefits. Please open an issue at https://github.com/duobaseio/forui/issues if you use it and think otherwise.') bool contentScrollHandles = false,
  39. ScrollPhysics contentPhysics = const ClampingScrollPhysics(),
  40. FItemDivider contentDivider = .none,
  41. Key? key,
})

Creates a FSelect from the given items.

For more control over the appearance of items, use FSelect.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 FSelect({
  required Map<String, T> items,
  FSelectControl<T>? control,
  FPopoverControl popoverControl = const .managed(),
  FSelectStyle Function(FSelectStyle style)? style,
  bool autofocus = false,
  FocusNode? focusNode,
  FFieldBuilder<FSelectStyle> builder = _fieldBuilder,
  FFieldIconBuilder<FSelectStyle>? prefixBuilder,
  FFieldIconBuilder<FSelectStyle>? suffixBuilder = defaultIconBuilder,
  Widget? label,
  Widget? description,
  bool enabled = true,
  FormFieldSetter<T>? onSaved,
  VoidCallback? onReset,
  AutovalidateMode autovalidateMode = .onUnfocus,
  String? forceErrorText,
  FormFieldValidator<T> validator = _defaultValidator,
  Widget Function(BuildContext context, String message) errorBuilder = FFormFieldProperties.defaultErrorBuilder,
  String? hint,
  TextAlign textAlign = .start,
  TextAlignVertical? textAlignVertical,
  TextDirection? textDirection,
  bool expands = false,
  MouseCursor mouseCursor = .defer,
  bool canRequestFocus = true,
  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 = .zero,
  FPopoverHideRegion contentHideRegion = .excludeChild,
  Object? contentGroupId,
  bool autoHide = true,
  Widget Function(BuildContext context, FSelectStyle style) contentEmptyBuilder = defaultContentEmptyBuilder,
  ScrollController? contentScrollController,
  @Deprecated(
    'Usage of scroll handles seem to be low while its maintenance burden far outweighs its benefits. Please open an issue at https://github.com/duobaseio/forui/issues if you use it and think otherwise.',
  )
  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,
    builder: builder,
    prefixBuilder: prefixBuilder,
    suffixBuilder: suffixBuilder,
    label: label,
    description: description,
    enabled: enabled,
    onSaved: onSaved,
    onReset: onReset,
    autovalidateMode: autovalidateMode,
    forceErrorText: forceErrorText,
    validator: validator,
    errorBuilder: errorBuilder,
    format: (value) => inverse[value]!,
    hint: hint,
    textAlign: textAlign,
    textAlignVertical: textAlignVertical,
    textDirection: textDirection,
    expands: expands,
    mouseCursor: mouseCursor,
    canRequestFocus: canRequestFocus,
    clearable: clearable,
    contentAnchor: contentAnchor,
    fieldAnchor: fieldAnchor,
    contentConstraints: contentConstraints,
    contentSpacing: contentSpacing,
    contentOverflow: contentOverflow,
    contentOffset: contentOffset,
    contentHideRegion: contentHideRegion,
    contentGroupId: contentGroupId,
    autoHide: autoHide,
    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)],
  );
}