MutableText constructor

const MutableText(
  1. String value, {
  2. Key? key,
  3. MainAxisSize mainAxisSize = MainAxisSize.min,
  4. ValueChanged<String>? onChanged,
  5. bool autoCorrect = true,
  6. int? minLines,
  7. TextStyle? style,
  8. int? maxLines,
  9. Locale? locale,
  10. Color? selectionColor,
  11. TextOverflow? overflow,
  12. String? semanticsLabel,
  13. List<TextInputFormatter>? inputFormatters,
  14. bool? softWrap,
  15. StrutStyle? strutStyle,
  16. TextAlign? textAlign,
  17. TextDirection? textDirection,
  18. TextHeightBehavior? textHeightBehavior,
  19. TextScaler? textScaler,
  20. TextWidthBasis? textWidthBasis,
  21. int? maxLength,
  22. Widget? placeholder,
  23. Widget? overrideButtonContent,
  24. double buttonGapWidth = 4,
  25. VoidCallback? onEditingComplete,
  26. VoidCallback? onEditingStarted,
  27. EditButtonType buttonType = EditButtonType.pencil,
  28. String labelBuilder(
    1. String
    )?,
  29. bool border = false,
})

Constructs a MutableText widget with the specified initial text value and optional editing configurations.

Parameters and Initialization:

  • The required value sets the initial display text, which becomes the starting point for editing.
  • onChanged (optional) is invoked with the new text value when editing completes via submission or escape.
  • onEditingComplete (optional) is called after editing ends, useful for form validation or state updates in ArcaneField.
  • onEditingStarted (optional) triggers on edit initiation, allowing pre-edit logic like focus management.
  • Styling options like style, textAlign, maxLines, minLines, overflow, and selectionColor customize appearance and behavior, defaulting to Flutter's Text standards.
  • Input controls include autoCorrect (defaults to true), inputFormatters for validation (e.g., numeric only), and maxLength with enforcement.
  • Edit UI: buttonType defaults to EditButtonType.pencil using IconButton; set to ghost for GhostButton. buttonGapWidth (default 4) spaces the button, and overrideButtonContent allows custom icons.
  • Layout: mainAxisSize controls row sizing (min or max), affecting text flexibility in containers.
  • Advanced: placeholder shows hint text during editing, labelBuilder transforms value for display (e.g., formatting numbers), border enables default TextField border, and accessibility via semanticsLabel, locale, softWrap, strutStyle, textDirection, textHeightBehavior, textScaler, textWidthBasis.

Usage Example:

MutableText(
  'Initial Text',
  onChanged: (newValue) => setState(() => myText = newValue),
  style: ArcaneTheme.of(context).bodyLarge,
  maxLines: 3,
  buttonType: EditButtonType.ghost,
)

This creates an editable text block that updates state on change and uses ghost button styling, integrating with ArcaneTheme for consistent theming.

If onChanged is null, no edit button is shown, rendering as a static Text. For form integration, wrap in FieldWrapper or use with ArcaneFieldProvider for reactive updates.

Implementation

const MutableText(this.value,
    {super.key,
    this.mainAxisSize = MainAxisSize.min,
    this.onChanged,
    this.autoCorrect = true,
    this.minLines,
    this.style,
    this.maxLines,
    this.locale,
    this.selectionColor,
    this.overflow,
    this.semanticsLabel,
    this.inputFormatters,
    this.softWrap,
    this.strutStyle,
    this.textAlign,
    this.textDirection,
    this.textHeightBehavior,
    this.textScaler,
    this.textWidthBasis,
    this.maxLength,
    this.placeholder,
    this.overrideButtonContent,
    this.buttonGapWidth = 4,
    this.onEditingComplete,
    this.onEditingStarted,
    this.buttonType = EditButtonType.pencil,
    this.labelBuilder,
    this.border = false});