TextField constructor

const TextField({
  1. Key? key,
  2. Object groupId = EditableText,
  3. TextEditingController? controller,
  4. String? initialValue,
  5. FocusNode? focusNode,
  6. UndoHistoryController? undoController,
  7. BoxDecoration? decoration,
  8. EdgeInsetsGeometry? padding,
  9. Widget? placeholder,
  10. @Deprecated('Use InputFeature.leading instead') Widget? leading,
  11. @Deprecated('Use InputFeature.trailing instead') Widget? trailing,
  12. CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
  13. String? clearButtonSemanticLabel,
  14. TextInputType? keyboardType,
  15. TextInputAction? textInputAction,
  16. TextCapitalization textCapitalization = TextCapitalization.none,
  17. TextStyle? style,
  18. StrutStyle? strutStyle,
  19. TextAlign textAlign = TextAlign.start,
  20. TextAlignVertical? textAlignVertical,
  21. TextDirection? textDirection,
  22. bool readOnly = false,
  23. bool? showCursor,
  24. bool autofocus = false,
  25. String obscuringCharacter = '•',
  26. bool obscureText = false,
  27. bool autocorrect = true,
  28. SmartDashesType? smartDashesType,
  29. SmartQuotesType? smartQuotesType,
  30. bool enableSuggestions = true,
  31. int? maxLines = 1,
  32. int? minLines,
  33. bool expands = false,
  34. int? maxLength,
  35. MaxLengthEnforcement? maxLengthEnforcement,
  36. ValueChanged<String>? onChanged,
  37. VoidCallback? onEditingComplete,
  38. ValueChanged<String>? onSubmitted,
  39. TapRegionCallback? onTapOutside,
  40. TapRegionCallback? onTapUpOutside,
  41. List<TextInputFormatter>? inputFormatters,
  42. bool enabled = true,
  43. double cursorWidth = 2.0,
  44. double? cursorHeight,
  45. Radius cursorRadius = const Radius.circular(2.0),
  46. bool cursorOpacityAnimates = true,
  47. Color? cursorColor,
  48. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  49. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  50. Brightness? keyboardAppearance,
  51. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  52. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  53. bool? enableInteractiveSelection,
  54. TextSelectionControls? selectionControls,
  55. GestureTapCallback? onTap,
  56. ScrollController? scrollController,
  57. AlignmentGeometry stackAlignment = AlignmentDirectional.topCenter,
  58. ScrollPhysics? scrollPhysics,
  59. Iterable<String>? autofillHints = const [],
  60. ContentInsertionConfiguration? contentInsertionConfiguration,
  61. Clip clipBehavior = Clip.hardEdge,
  62. String? restorationId,
  63. bool stylusHandwritingEnabled = EditableText.defaultStylusHandwritingEnabled,
  64. bool enableIMEPersonalizedLearning = true,
  65. EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder,
  66. SpellCheckConfiguration? spellCheckConfiguration,
  67. TextMagnifierConfiguration? magnifierConfiguration,
  68. String? hintText,
  69. bool border = true,
  70. BorderRadiusGeometry? borderRadius,
  71. bool filled = false,
  72. WidgetStatesController? statesController,
  73. List<InputFeature> features = const [],
  74. List<TextInputFormatter>? submitFormatters = const [],
})

Implementation

const TextField({
  super.key,
  this.groupId = EditableText,
  this.controller,
  this.initialValue,
  this.focusNode,
  this.undoController,
  this.decoration,
  this.padding,
  this.placeholder,
  @Deprecated('Use InputFeature.leading instead') this.leading,
  @Deprecated('Use InputFeature.trailing instead') this.trailing,
  this.crossAxisAlignment = CrossAxisAlignment.center,
  this.clearButtonSemanticLabel,
  TextInputType? keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.style,
  this.strutStyle,
  this.textAlign = TextAlign.start,
  this.textAlignVertical,
  this.textDirection,
  this.readOnly = false,
  this.showCursor,
  this.autofocus = false,
  this.obscuringCharacter = '•',
  this.obscureText = false,
  this.autocorrect = true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  this.enableSuggestions = true,
  this.maxLines = 1,
  this.minLines,
  this.expands = false,
  this.maxLength,
  this.maxLengthEnforcement,
  this.onChanged,
  this.onEditingComplete,
  this.onSubmitted,
  this.onTapOutside,
  this.onTapUpOutside,
  this.inputFormatters,
  this.enabled = true,
  this.cursorWidth = 2.0,
  this.cursorHeight,
  this.cursorRadius = const Radius.circular(2.0),
  this.cursorOpacityAnimates = true,
  this.cursorColor,
  this.selectionHeightStyle = ui.BoxHeightStyle.tight,
  this.selectionWidthStyle = ui.BoxWidthStyle.tight,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.dragStartBehavior = DragStartBehavior.start,
  bool? enableInteractiveSelection,
  this.selectionControls,
  this.onTap,
  this.scrollController,
  this.stackAlignment = AlignmentDirectional.topCenter,
  this.scrollPhysics,
  this.autofillHints = const [],
  this.contentInsertionConfiguration,
  this.clipBehavior = Clip.hardEdge,
  this.restorationId,
  this.stylusHandwritingEnabled =
      EditableText.defaultStylusHandwritingEnabled,
  this.enableIMEPersonalizedLearning = true,
  this.contextMenuBuilder = _defaultContextMenuBuilder,
  this.spellCheckConfiguration,
  this.magnifierConfiguration,
  this.hintText,
  this.border = true,
  this.borderRadius,
  this.filled = false,
  this.statesController,
  this.features = const [],
  this.submitFormatters = const [],
})  : assert(obscuringCharacter.length == 1),
      smartDashesType = smartDashesType ??
          (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
      smartQuotesType = smartQuotesType ??
          (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
      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 || (maxLines == null && minLines == null),
        'minLines and maxLines must be null when expands is true.',
      ),
      assert(!obscureText || maxLines == 1,
          'Obscured fields cannot be multiline.'),
      assert(maxLength == null || maxLength > 0),
      // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
      assert(
        !identical(textInputAction, TextInputAction.newline) ||
            maxLines == 1 ||
            !identical(keyboardType, TextInputType.text),
        'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.',
      ),
      keyboardType = keyboardType ??
          (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
      enableInteractiveSelection =
          enableInteractiveSelection ?? (!readOnly || !obscureText);