TextFormBox constructor
TextFormBox({
- Key? key,
- TextEditingController? controller,
- String? initialValue,
- FocusNode? focusNode,
- TextInputType? keyboardType,
- TextCapitalization textCapitalization = TextCapitalization.none,
- TextInputAction? textInputAction,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextDirection? textDirection,
- TextAlign textAlign = TextAlign.start,
- TextAlignVertical? textAlignVertical,
- bool autofocus = false,
- bool readOnly = false,
- bool? showCursor,
- String obscuringCharacter = '•',
- bool obscureText = false,
- bool autocorrect = true,
- SmartDashesType? smartDashesType,
- SmartQuotesType? smartQuotesType,
- bool enableSuggestions = true,
- int? maxLines = 1,
- int? minLines,
- bool expands = false,
- int? maxLength,
- EdgeInsetsGeometry padding = kTextBoxPadding,
- ValueChanged<
String> ? onChanged, - GestureTapCallback? onTap,
- TapRegionCallback? onTapOutside,
- VoidCallback? onEditingComplete,
- ValueChanged<
String> ? onFieldSubmitted, - FormFieldSetter<
String> ? onSaved, - FormFieldValidator<
String> ? validator, - List<
TextInputFormatter> ? inputFormatters, - bool enabled = true,
- double cursorWidth = 2.0,
- double? cursorHeight,
- Radius cursorRadius = const Radius.circular(2.0),
- Color? cursorColor,
- Brightness? keyboardAppearance,
- EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
- bool? enableInteractiveSelection,
- TextSelectionControls? selectionControls,
- ScrollPhysics? scrollPhysics,
- Iterable<
String> ? autofillHints, - AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- String? placeholder,
- TextStyle? placeholderStyle,
- ScrollController? scrollController,
- Clip clipBehavior = Clip.antiAlias,
- Widget? prefix,
- OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
- Widget? suffix,
- OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- String? restorationId,
- MaxLengthEnforcement? maxLengthEnforcement,
- BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
- BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
- BoxDecoration? decoration,
- bool enableIMEPersonalizedLearning = true,
- MouseCursor? mouseCursor,
- bool scribbleEnabled = true,
- Color? highlightColor,
- Color? errorHighlightColor,
- Color? unfocusedColor,
- EditableTextContextMenuBuilder? contextMenuBuilder,
- TextMagnifierConfiguration? magnifierConfiguration,
- SpellCheckConfiguration? spellCheckConfiguration,
Creates a FormField that contains a TextBox.
When a controller is specified, initialValue
must be null (the
default). If controller is null, then a TextEditingController
will be constructed automatically and its text
will be initialized
to initialValue
or the empty string.
For documentation about the various parameters, see the TextBox class and TextBox.new, the constructor.
Implementation
TextFormBox({
super.key,
super.controller,
String? initialValue,
FocusNode? focusNode,
TextInputType? keyboardType,
TextCapitalization textCapitalization = TextCapitalization.none,
TextInputAction? textInputAction,
TextStyle? style,
StrutStyle? strutStyle,
TextDirection? textDirection,
TextAlign textAlign = TextAlign.start,
TextAlignVertical? textAlignVertical,
bool autofocus = false,
bool readOnly = false,
bool? showCursor,
String obscuringCharacter = '•',
bool obscureText = false,
bool autocorrect = true,
SmartDashesType? smartDashesType,
SmartQuotesType? smartQuotesType,
bool enableSuggestions = true,
int? maxLines = 1,
int? minLines,
bool expands = false,
int? maxLength,
EdgeInsetsGeometry padding = kTextBoxPadding,
ValueChanged<String>? onChanged,
GestureTapCallback? onTap,
TapRegionCallback? onTapOutside,
VoidCallback? onEditingComplete,
ValueChanged<String>? onFieldSubmitted,
super.onSaved,
super.validator,
List<TextInputFormatter>? inputFormatters,
super.enabled = true,
double cursorWidth = 2.0,
double? cursorHeight,
Radius cursorRadius = const Radius.circular(2.0),
Color? cursorColor,
Brightness? keyboardAppearance,
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool? enableInteractiveSelection,
TextSelectionControls? selectionControls,
ScrollPhysics? scrollPhysics,
Iterable<String>? autofillHints,
super.autovalidateMode = AutovalidateMode.disabled,
String? placeholder,
TextStyle? placeholderStyle,
ScrollController? scrollController,
Clip clipBehavior = Clip.antiAlias,
Widget? prefix,
OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
Widget? suffix,
OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
String? restorationId,
MaxLengthEnforcement? maxLengthEnforcement,
ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
BoxDecoration? decoration,
bool enableIMEPersonalizedLearning = true,
MouseCursor? mouseCursor,
bool scribbleEnabled = true,
Color? highlightColor,
Color? errorHighlightColor,
Color? unfocusedColor,
EditableTextContextMenuBuilder? contextMenuBuilder,
TextMagnifierConfiguration? magnifierConfiguration,
SpellCheckConfiguration? spellCheckConfiguration,
}) : assert(initialValue == null || controller == null),
assert(obscuringCharacter.length == 1),
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),
super(
initialValue:
controller != null ? controller.text : (initialValue ?? ''),
builder: (FormFieldState<String> field) {
assert(debugCheckHasFluentTheme(field.context));
final theme = FluentTheme.of(field.context);
final state = field as TextFormBoxState;
void onChangedHandler(String value) {
field.didChange(value);
if (onChanged != null) {
onChanged(value);
}
}
return UnmanagedRestorationScope(
bucket: field.bucket,
child: FormRow(
padding: EdgeInsets.zero,
error:
(field.errorText == null) ? null : Text(field.errorText!),
child: TextBox(
controller: state._effectiveController,
focusNode: focusNode,
keyboardType: keyboardType,
textInputAction: textInputAction,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textAlignVertical: textAlignVertical,
textCapitalization: textCapitalization,
autofocus: autofocus,
readOnly: readOnly,
showCursor: showCursor,
obscuringCharacter: obscuringCharacter,
obscureText: obscureText,
autocorrect: autocorrect,
smartDashesType: smartDashesType ??
(obscureText
? SmartDashesType.disabled
: SmartDashesType.enabled),
smartQuotesType: smartQuotesType ??
(obscureText
? SmartQuotesType.disabled
: SmartQuotesType.enabled),
enableSuggestions: enableSuggestions,
maxLines: maxLines,
minLines: minLines,
expands: expands,
maxLength: maxLength,
onChanged: onChangedHandler,
onTap: onTap,
onTapOutside: onTapOutside,
onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters,
enabled: enabled,
cursorWidth: cursorWidth,
cursorHeight: cursorHeight,
cursorColor: cursorColor,
cursorRadius: cursorRadius,
scrollPadding: scrollPadding,
scrollPhysics: scrollPhysics,
keyboardAppearance: keyboardAppearance,
enableInteractiveSelection: enableInteractiveSelection,
autofillHints: autofillHints,
placeholder: placeholder,
placeholderStyle: placeholderStyle,
scrollController: scrollController,
clipBehavior: clipBehavior,
prefix: prefix,
prefixMode: prefixMode,
suffix: suffix,
suffixMode: suffixMode,
highlightColor: (field.errorText == null)
? highlightColor
: errorHighlightColor ??
Colors.red.defaultBrushFor(theme.brightness),
unfocusedColor: unfocusedColor,
dragStartBehavior: dragStartBehavior,
padding: padding,
maxLengthEnforcement: maxLengthEnforcement,
restorationId: restorationId,
selectionHeightStyle: selectionHeightStyle,
selectionWidthStyle: selectionWidthStyle,
decoration: decoration,
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
scribbleEnabled: scribbleEnabled,
textDirection: textDirection,
selectionControls: selectionControls,
contextMenuBuilder: contextMenuBuilder,
magnifierConfiguration: magnifierConfiguration,
spellCheckConfiguration: spellCheckConfiguration,
),
),
);
},
);