FormBuilderTypeAhead<T> constructor Null safety

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

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

Implementation

FormBuilderTypeAhead({
  Key? key,
  //From Super
  required String name,
  FormFieldValidator<T>? validator,
  T? initialValue,
  InputDecoration decoration = const InputDecoration(),
  ValueChanged<T?>? onChanged,
  ValueTransformer<T?>? valueTransformer,
  bool enabled = true,
  FormFieldSetter<T>? onSaved,
  AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
  VoidCallback? onReset,
  FocusNode? focusNode,
  required this.itemBuilder,
  required this.suggestionsCallback,
  this.getImmediateSuggestions = false,
  this.selectionToTextTransformer,
  this.errorBuilder,
  this.noItemsFoundBuilder,
  this.loadingBuilder,
  this.debounceDuration = const Duration(milliseconds: 300),
  this.suggestionsBoxDecoration = const SuggestionsBoxDecoration(),
  this.suggestionsBoxVerticalOffset = 5.0,
  this.textFieldConfiguration = const TextFieldConfiguration(),
  this.transitionBuilder,
  this.animationDuration = const Duration(milliseconds: 500),
  this.animationStart = 0.25,
  this.direction = AxisDirection.down,
  this.hideOnLoading = false,
  this.hideOnEmpty = false,
  this.hideOnError = false,
  this.hideSuggestionsOnKeyboardHide = true,
  this.keepSuggestionsOnLoading = true,
  this.autoFlipDirection = false,
  this.suggestionsBoxController,
  this.keepSuggestionsOnSuggestionSelected = false,
  this.onSuggestionSelected,
  this.controller,
  this.hideKeyboard = false,
  this.scrollController,
})  : assert(T == String || selectionToTextTransformer != null),
      super(
        key: key,
        initialValue: initialValue,
        name: name,
        validator: validator,
        valueTransformer: valueTransformer,
        onChanged: onChanged,
        autovalidateMode: autovalidateMode,
        onSaved: onSaved,
        enabled: enabled,
        onReset: onReset,
        decoration: decoration,
        focusNode: focusNode,
        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.subtitle1!.copyWith(
                      color: theme.disabledColor,
                    ),
              focusNode: state.effectiveFocusNode,
              decoration: state.decoration,
            ),
            // 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,
          );
        },
      );