TextArea constructor

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

Creates a TextArea with comprehensive configuration options.

The text area supports both controlled and uncontrolled modes. Use controller for controlled mode or initialValue for uncontrolled mode. The text area can be configured for resizing, styling, and various text input behaviors.

Parameters:

  • expandableHeight (bool, default: false): Enable vertical resizing
  • expandableWidth (bool, default: false): Enable horizontal resizing
  • initialHeight (double, default: 100): Starting height in pixels
  • initialWidth (double, default: double.infinity): Starting width in pixels
  • enabled (bool, default: true): Whether the text area accepts input
  • readOnly (bool, default: false): Whether the text is read-only
  • obscureText (bool, default: false): Whether to hide the text
  • obscuringCharacter (String, default: '•'): Character for hiding text
  • textAlign (TextAlign, default: TextAlign.start): Horizontal text alignment
  • minWidth (double, default: 100): Minimum width constraint
  • minHeight (double, default: 100): Minimum height constraint
  • maxWidth (double, default: double.infinity): Maximum width constraint
  • maxHeight (double, default: double.infinity): Maximum height constraint
  • textAlignVertical (TextAlignVertical, default: top): Vertical text alignment
  • clipBehavior (Clip, default: Clip.hardEdge): Content clipping behavior
  • autofocus (bool, default: false): Whether to auto-focus on creation

Example:

TextArea(
  placeholder: Text('Enter your message'),
  expandableHeight: true,
  minHeight: 100,
  maxHeight: 300,
  onChanged: (text) => _handleTextChange(text),
);

Implementation

const TextArea({
  super.key,
  super.groupId,
  super.controller,
  super.focusNode,
  super.decoration,
  super.padding,
  super.placeholder,
  super.crossAxisAlignment,
  super.clearButtonSemanticLabel,
  super.keyboardType,
  super.textInputAction,
  super.textCapitalization,
  super.style,
  super.strutStyle,
  super.textAlign,
  super.textAlignVertical,
  super.textDirection,
  super.readOnly,
  super.showCursor,
  super.autofocus,
  super.obscuringCharacter,
  super.obscureText,
  super.autocorrect,
  super.smartDashesType,
  super.smartQuotesType,
  super.enableSuggestions,
  super.maxLines,
  super.minLines,
  super.expands,
  super.maxLength,
  super.maxLengthEnforcement,
  super.onChanged,
  super.onEditingComplete,
  super.onSubmitted,
  super.onTapOutside,
  super.onTapUpOutside,
  super.inputFormatters,
  super.enabled,
  super.cursorWidth,
  super.cursorHeight,
  super.cursorRadius,
  super.cursorOpacityAnimates,
  super.cursorColor,
  super.selectionHeightStyle,
  super.selectionWidthStyle,
  super.keyboardAppearance,
  super.scrollPadding,
  super.enableInteractiveSelection,
  super.selectionControls,
  super.dragStartBehavior,
  super.scrollController,
  super.scrollPhysics,
  super.onTap,
  super.autofillHints,
  super.clipBehavior,
  super.restorationId,
  super.stylusHandwritingEnabled,
  super.enableIMEPersonalizedLearning,
  super.contentInsertionConfiguration,
  super.contextMenuBuilder,
  super.initialValue,
  super.hintText,
  super.border,
  super.borderRadius,
  super.filled,
  super.statesController,
  super.magnifierConfiguration,
  super.spellCheckConfiguration,
  super.undoController,
  super.features,
  super.submitFormatters,
  super.skipInputFeatureFocusTraversal,
  this.expandableHeight = false,
  this.expandableWidth = false,
  this.initialHeight = 100,
  this.initialWidth = double.infinity,
  this.onHeightChanged,
  this.onWidthChanged,
  this.minWidth = 100,
  this.minHeight = 100,
  this.maxWidth = double.infinity,
  this.maxHeight = double.infinity,
});