FormBuilderTypeAhead<T> constructor

FormBuilderTypeAhead<T>({
  1. Key? key,
  2. AutovalidateMode? autovalidateMode,
  3. bool enabled = true,
  4. FocusNode? focusNode,
  5. FormFieldSetter<T>? onSaved,
  6. FormFieldValidator<T>? validator,
  7. InputDecoration decoration = const InputDecoration(),
  8. T? initialValue,
  9. ValueChanged<T?>? onChanged,
  10. ValueTransformer<T?>? valueTransformer,
  11. VoidCallback? onReset,
  12. required String name,
  13. required ItemBuilder<T> itemBuilder,
  14. required SuggestionsCallback<T> suggestionsCallback,
  15. Duration animationDuration = const Duration(milliseconds: 500),
  16. double animationStart = 0.25,
  17. bool autoFlipDirection = false,
  18. TextEditingController? controller,
  19. Duration debounceDuration = const Duration(milliseconds: 300),
  20. AxisDirection direction = AxisDirection.down,
  21. ErrorBuilder? errorBuilder,
  22. bool getImmediateSuggestions = false,
  23. bool hideKeyboard = false,
  24. bool hideOnEmpty = false,
  25. bool hideOnError = false,
  26. bool hideOnLoading = false,
  27. bool hideSuggestionsOnKeyboardHide = true,
  28. bool keepSuggestionsOnLoading = true,
  29. bool keepSuggestionsOnSuggestionSelected = false,
  30. WidgetBuilder? loadingBuilder,
  31. WidgetBuilder? noItemsFoundBuilder,
  32. SuggestionSelectionCallback<T>? onSuggestionSelected,
  33. ScrollController? scrollController,
  34. SelectionToTextTransformer<T>? selectionToTextTransformer,
  35. SuggestionsBoxController? suggestionsBoxController,
  36. SuggestionsBoxDecoration suggestionsBoxDecoration = const SuggestionsBoxDecoration(),
  37. double suggestionsBoxVerticalOffset = 5.0,
  38. TextFieldConfiguration textFieldConfiguration = const TextFieldConfiguration(),
  39. AnimationTransitionBuilder? transitionBuilder,
  40. bool autoFlipListDirection = true,
  41. double autoFlipMinHeight = 64.0,
  42. bool hideKeyboardOnDrag = false,
  43. bool ignoreAccessibleNavigation = false,
  44. bool intercepting = false,
  45. IndexedWidgetBuilder? itemSeparatorBuilder,
  46. LayoutArchitecture? layoutArchitecture,
  47. int minCharsForSuggestions = 0,
  48. void onSuggestionsBoxToggle(
    1. bool
    )?,
})

Creates text field that auto-completes user input from a list of items

Implementation

FormBuilderTypeAhead({
  super.key,
  super.autovalidateMode,
  super.enabled,
  super.focusNode,
  super.onSaved,
  super.validator,
  super.decoration,
  super.initialValue,
  super.onChanged,
  super.valueTransformer,
  super.onReset,
  required super.name,
  required this.itemBuilder,
  required this.suggestionsCallback,
  this.animationDuration = const Duration(milliseconds: 500),
  this.animationStart = 0.25,
  this.autoFlipDirection = false,
  this.controller,
  this.debounceDuration = const Duration(milliseconds: 300),
  this.direction = AxisDirection.down,
  this.errorBuilder,
  this.getImmediateSuggestions = false,
  this.hideKeyboard = false,
  this.hideOnEmpty = false,
  this.hideOnError = false,
  this.hideOnLoading = false,
  this.hideSuggestionsOnKeyboardHide = true,
  this.keepSuggestionsOnLoading = true,
  this.keepSuggestionsOnSuggestionSelected = false,
  this.loadingBuilder,
  this.noItemsFoundBuilder,
  this.onSuggestionSelected,
  this.scrollController,
  this.selectionToTextTransformer,
  this.suggestionsBoxController,
  this.suggestionsBoxDecoration = const SuggestionsBoxDecoration(),
  this.suggestionsBoxVerticalOffset = 5.0,
  this.textFieldConfiguration = const TextFieldConfiguration(),
  this.transitionBuilder,
  this.autoFlipListDirection = true,
  this.autoFlipMinHeight = 64.0,
  this.hideKeyboardOnDrag = false,
  this.ignoreAccessibleNavigation = false,
  this.intercepting = false,
  this.itemSeparatorBuilder,
  this.layoutArchitecture,
  this.minCharsForSuggestions = 0,
  this.onSuggestionsBoxToggle,
})  : assert(T == String || selectionToTextTransformer != null),
      super(
        builder: (FormFieldState<T?> field) {
          final state = field as FormBuilderTypeAheadState<T>;
          final theme = Theme.of(state.context);

          return TypeAheadField<T>(
            textFieldConfiguration: textFieldConfiguration.copyWith(
              enabled: state.enabled,
              controller: state._typeAheadController,
              style: state.enabled
                  ? textFieldConfiguration.style
                  : theme.textTheme.titleMedium!.copyWith(
                      color: theme.disabledColor,
                    ),
              focusNode: state.effectiveFocusNode,
              decoration: state.decoration,
            ),
            autoFlipListDirection: autoFlipListDirection,
            autoFlipMinHeight: autoFlipMinHeight,
            hideKeyboardOnDrag: hideKeyboardOnDrag,
            ignoreAccessibleNavigation: ignoreAccessibleNavigation,
            intercepting: intercepting,
            itemSeparatorBuilder: itemSeparatorBuilder,
            layoutArchitecture: layoutArchitecture,
            minCharsForSuggestions: minCharsForSuggestions,
            onSuggestionsBoxToggle: onSuggestionsBoxToggle,
            // TODO HACK to satisfy strictness
            suggestionsCallback: suggestionsCallback,
            itemBuilder: itemBuilder,
            transitionBuilder: (context, suggestionsBox, controller) =>
                suggestionsBox,
            onSuggestionSelected: (T suggestion) {
              state.didChange(suggestion);
              onSuggestionSelected?.call(suggestion);
            },
            getImmediateSuggestions: getImmediateSuggestions,
            errorBuilder: errorBuilder,
            noItemsFoundBuilder: noItemsFoundBuilder,
            loadingBuilder: loadingBuilder,
            debounceDuration: debounceDuration,
            suggestionsBoxDecoration: suggestionsBoxDecoration,
            suggestionsBoxVerticalOffset: suggestionsBoxVerticalOffset,
            animationDuration: animationDuration,
            animationStart: animationStart,
            direction: direction,
            hideOnLoading: hideOnLoading,
            hideOnEmpty: hideOnEmpty,
            hideOnError: hideOnError,
            hideSuggestionsOnKeyboardHide: hideSuggestionsOnKeyboardHide,
            keepSuggestionsOnLoading: keepSuggestionsOnLoading,
            autoFlipDirection: autoFlipDirection,
            suggestionsBoxController: suggestionsBoxController,
            keepSuggestionsOnSuggestionSelected:
                keepSuggestionsOnSuggestionSelected,
            hideKeyboard: hideKeyboard,
            scrollController: scrollController,
          );
        },
      );