mutable method
Widget
mutable(
- ValueChanged<
String> onChanged, { - Widget? placeholder,
- int? minLines,
- bool border = false,
- bool autoCorrect = true,
- EditButtonType buttonType = EditButtonType.pencil,
Extension on Flutter's Text widget to conveniently add mutable editing capabilities by wrapping it in a MutableText instance.
Key Features:
- Seamless Conversion: Transforms a static Text into an editable field with minimal boilerplate, preserving original properties like style, textAlign, and maxLines.
- Editing Configuration: Supports
onChanged
callback for updates,placeholder
for hints,minLines
for layout,border
for styling,autoCorrect
for UX, andbuttonType
for trigger style (ghost
orpencil
via IconButton). - Integration: Ideal for retrofitting existing text displays in components like
BasicCard
, Tile, or ArcaneField, enabling dynamic content without refactoring.
Usage Example:
Text('Static Text').mutable(
onChanged: (newValue) => updateModel(newValue),
placeholder: Text('Edit here...'),
buttonType: EditButtonType.ghost,
)
This converts the Text to editable, using GhostButton for initiation and integrating with form logic via onChanged
.
Note: The data from Text is used as the initial value
for MutableText, with null safety handled via empty string fallback.
Implementation
Widget mutable(ValueChanged<String> onChanged,
{Widget? placeholder,
int? minLines,
bool border = false,
bool autoCorrect = true,
EditButtonType buttonType = EditButtonType.pencil}) =>
MutableText(data ?? "",
placeholder: placeholder,
minLines: minLines,
maxLines: maxLines,
autoCorrect: autoCorrect,
buttonType: buttonType,
textAlign: textAlign,
style: style,
textWidthBasis: textWidthBasis,
textScaler: textScaler,
textHeightBehavior: textHeightBehavior,
textDirection: textDirection,
strutStyle: strutStyle,
softWrap: softWrap,
key: key,
semanticsLabel: semanticsLabel,
overflow: overflow,
selectionColor: selectionColor,
locale: locale,
border: border,
onChanged: onChanged);