TextFieldBlocBuilder constructor

const TextFieldBlocBuilder({
  1. Key? key,
  2. required TextFieldBloc textFieldBloc,
  3. bool enableOnlyWhenFormBlocCanSubmit = false,
  4. bool isEnabled = true,
  5. FieldBlocErrorBuilder? errorBuilder,
  6. SuffixButton? suffixButton,
  7. EdgeInsetsGeometry? padding,
  8. bool removeSuggestionOnLongPress = false,
  9. FocusNode? focusNode,
  10. InputDecoration decoration = const InputDecoration(),
  11. TextInputType? keyboardType,
  12. TextInputAction? textInputAction,
  13. TextCapitalization textCapitalization = TextCapitalization.none,
  14. @Deprecated('Use textStyle') TextStyle? style,
  15. TextStyle? textStyle,
  16. MaterialStateProperty<Color?>? textColor,
  17. StrutStyle? strutStyle,
  18. bool? obscureText,
  19. TextAlign? textAlign,
  20. TextAlignVertical? textAlignVertical,
  21. TextDirection? textDirection,
  22. bool? showCursor,
  23. bool autofocus = false,
  24. bool autocorrect = true,
  25. int? maxLines = 1,
  26. int? minLines,
  27. bool expands = false,
  28. int? maxLength,
  29. MaxLengthEnforcement maxLengthEnforced = MaxLengthEnforcement.enforced,
  30. ValueChanged<String>? onChanged,
  31. VoidCallback? onEditingComplete,
  32. ValueChanged<String>? onSubmitted,
  33. List<TextInputFormatter>? inputFormatters,
  34. double cursorWidth = 2.0,
  35. Radius? cursorRadius,
  36. Color? cursorColor,
  37. Brightness? keyboardAppearance,
  38. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  39. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  40. bool enableInteractiveSelection = true,
  41. GestureTapCallback? onTap,
  42. InputCounterWidgetBuilder? buildCounter,
  43. ScrollController? scrollController,
  44. ScrollPhysics? scrollPhysics,
  45. SuggestionsBoxDecoration? suggestionsBoxDecoration,
  46. TextStyle? suggestionTextStyle,
  47. Duration debounceSuggestionDuration = const Duration(milliseconds: 300),
  48. bool getImmediateSuggestions = true,
  49. Duration suggestionsAnimationDuration = const Duration(milliseconds: 700),
  50. FocusNode? nextFocusNode,
  51. bool hideOnLoadingSuggestions = false,
  52. bool hideOnEmptySuggestions = false,
  53. bool hideOnSuggestionsError = false,
  54. WidgetBuilder? loadingSuggestionsBuilder,
  55. WidgetBuilder? suggestionsNotFoundBuilder,
  56. ErrorBuilder? suggestionsErrorBuilder,
  57. bool keepSuggestionsOnLoading = false,
  58. bool showSuggestionsWhenIsEmpty = true,
  59. bool readOnly = false,
  60. ToolbarOptions? toolbarOptions,
  61. bool enableSuggestions = true,
  62. bool animateWhenCanShow = true,
  63. bool focusOnValidationFailed = true,
  64. Widget? obscureTextTrueIcon,
  65. Widget? obscureTextFalseIcon,
  66. Widget? clearTextIcon,
  67. Iterable<String>? autofillHints,
  68. Widget asyncValidatingIcon = const SizedBox(height: 24, width: 24, child: Padding(padding: EdgeInsets.all(8.0), child: CircularProgressIndicator(strokeWidth: 2.0))),
})

Creates a Material Design text field

If decoration is non-null (which is the default), the text field requires one of its ancestors to be a Material widget.

To remove the decoration entirely (including the extra padding introduced by the decoration to save space for the labels), set the decoration to null.

The maxLines property can be set to null to remove the restriction on the number of lines. By default, it is one, meaning this is a single-line text field. maxLines must not be zero.

The maxLength property is set to null by default, which means the number of characters allowed in the text field is not restricted. If maxLength is set a character counter will be displayed below the field showing how many characters have been entered. If the value is set to a positive integer it will also display the maximum allowed number of characters to be entered. If the value is set to TextFieldBlocBuilder.noMaxLength then only the current length is displayed.

After maxLength characters have been input, additional input is ignored, unless maxLengthEnforced is set to false. The text field enforces the length with a LengthLimitingTextInputFormatter, which is evaluated after the supplied inputFormatters, if any. The maxLength value must be either null or greater than zero.

If maxLengthEnforced is set to false, then more than maxLength characters may be entered, and the error counter and divider will switch to the decoration.errorStyle when the limit is exceeded.

The text cursor is not shown if showCursor is false or if showCursor is null (the default) and readOnly is true.

The textAlign, autofocus, obscureText, readOnly, autocorrect, maxLengthEnforced, scrollPadding, maxLines, and maxLength arguments must not be null.

See also:

  • maxLength, which discusses the precise meaning of "number of characters" and how it may differ from the intuitive meaning.

Implementation

const TextFieldBlocBuilder({
  Key? key,
  required this.textFieldBloc,
  this.enableOnlyWhenFormBlocCanSubmit = false,
  this.isEnabled = true,
  this.errorBuilder,
  this.suffixButton,
  this.padding,
  this.removeSuggestionOnLongPress = false,
  this.focusNode,
  this.decoration = const InputDecoration(),
  TextInputType? keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  @Deprecated('Use textStyle') TextStyle? style,
  TextStyle? textStyle,
  this.textColor,
  this.strutStyle,
  this.obscureText,
  this.textAlign,
  this.textAlignVertical,
  this.textDirection,
  this.showCursor,
  this.autofocus = false,
  this.autocorrect = true,
  this.maxLines = 1,
  this.minLines,
  this.expands = false,
  this.maxLength,
  this.maxLengthEnforced = MaxLengthEnforcement.enforced,
  this.onChanged,
  this.onEditingComplete,
  this.onSubmitted,
  this.inputFormatters,
  this.cursorWidth = 2.0,
  this.cursorRadius,
  this.cursorColor,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.dragStartBehavior = DragStartBehavior.start,
  this.enableInteractiveSelection = true,
  this.onTap,
  this.buildCounter,
  this.scrollController,
  this.scrollPhysics,
  this.suggestionsBoxDecoration,
  this.suggestionTextStyle,
  this.debounceSuggestionDuration = const Duration(milliseconds: 300),
  this.getImmediateSuggestions = true,
  this.suggestionsAnimationDuration = const Duration(milliseconds: 700),
  this.nextFocusNode,
  this.hideOnLoadingSuggestions = false,
  this.hideOnEmptySuggestions = false,
  this.hideOnSuggestionsError = false,
  this.loadingSuggestionsBuilder,
  this.suggestionsNotFoundBuilder,
  this.suggestionsErrorBuilder,
  this.keepSuggestionsOnLoading = false,
  this.showSuggestionsWhenIsEmpty = true,
  this.readOnly = false,
  this.toolbarOptions,
  this.enableSuggestions = true,
  this.animateWhenCanShow = true,
  this.focusOnValidationFailed = true,
  this.obscureTextTrueIcon,
  this.obscureTextFalseIcon,
  this.clearTextIcon,
  this.autofillHints,
  this.asyncValidatingIcon = const SizedBox(
    height: 24,
    width: 24,
    child: Padding(
      padding: EdgeInsets.all(8.0),
      child: CircularProgressIndicator(
        strokeWidth: 2.0,
      ),
    ),
  ),
})  : assert(maxLines == null || maxLines > 0),
      assert(minLines == null || minLines > 0),
      assert(
        (maxLines == null) || (minLines == null) || (maxLines >= minLines),
        "minLines can't be greater than maxLines",
      ),
      assert(
        !expands || (minLines == null),
        'minLines and maxLines must be null when expands is true.',
      ),
      assert(maxLength == null ||
          maxLength == TextFieldBlocBuilder.noMaxLength ||
          maxLength > 0),
      keyboardType = keyboardType ??
          (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
      textStyle = textStyle ?? style,
      super(key: key);