Implementation
@override
Widget render(BuildContext context) {
var cursorStyle = style.cursorStyle;
var selectionStyle = style.selectionStyle;
var editText = EditableText(
key: _editableTextKey,
controller: innerController,
focusNode: _focusNode,
readOnly: widget.readOnly || widget.disabled,
obscureText: _obscureText,
obscuringCharacter: style.obscuringCharacter!,
style: _obscureText ? style.obscureTextStyle! : style.textStyle!,
textAlign: widget.textAlign,
maxLines: _obscureText ? 1 : widget.maxLines,
minLines: widget.minLines,
cursorColor: cursorStyle!.color!,
cursorWidth: cursorStyle.width!,
cursorHeight: cursorStyle.height,
cursorRadius: cursorStyle.radius != null
? Radius.circular(cursorStyle.radius!)
: null,
cursorOpacityAnimates: cursorStyle.opacityAnimates,
cursorOffset: cursorStyle.offset,
backgroundCursorColor: cursorStyle.color!,
paintCursorAboveText: style.cursorStyle?.above == true,
keyboardType: widget.keyboardType,
textInputAction: widget.inputAction,
keyboardAppearance: style.keyboardStyle?.appearance ?? Brightness.light,
inputFormatters: [
if (widget.maxLength != null)
LengthLimitingTextInputFormatter(widget.maxLength!),
...(widget.formatters ?? [])
],
autocorrect: widget.autocorrect,
enableSuggestions: !_obscureText,
spellCheckConfiguration: widget.spellCheckConfiguration,
enableInteractiveSelection: _showSelectionHandles,
selectionColor: selectionStyle?.color,
selectionControls: switch (defaultTargetPlatform) {
TargetPlatform.iOS => cupertinoTextSelectionHandleControls,
TargetPlatform.android => materialTextSelectionHandleControls,
TargetPlatform.fuchsia => materialTextSelectionHandleControls,
TargetPlatform.linux => desktopTextSelectionHandleControls,
TargetPlatform.macOS => cupertinoTextSelectionHandleControls,
TargetPlatform.windows => desktopTextSelectionHandleControls,
},
selectionHeightStyle: selectionStyle?.heightStyle ?? BoxHeightStyle.tight,
selectionWidthStyle: selectionStyle?.widthStyle ?? BoxWidthStyle.tight,
showSelectionHandles: _showSelectionHandles,
onSelectionChanged: _handleSelectionChanged,
onSelectionHandleTapped: _handleSelectionHandleTapped,
scrollController: widget.scrollController,
scrollPhysics: widget.scrollPhysics,
scrollPadding: EdgeInsets.zero,
dragStartBehavior: widget.dragStartBehavior,
onChanged: _handlerOnChange,
contextMenuBuilder:
widget.contextMenuBuilder ?? _defaultContextMenuBuilder,
onEditingComplete: widget.onEditingComplete,
onSubmitted: widget.onSubmitted,
onAppPrivateCommand: widget.onAppPrivateCommand,
undoController: widget.undoController,
magnifierConfiguration: widget.magnifierConfiguration ??
TextMagnifier.adaptiveMagnifierConfiguration,
rendererIgnoresPointer: true,
clipBehavior: widget.clipBehavior,
);
return AntdBox(
disabled: widget.disabled,
style: style.bodyStyle,
onTap: widget.onTap,
focusNode: _focusNode,
onFocus: (value) {
if (!value) {
widget.setValue(
context, innerController.text, AntdFormTrigger.onFocus);
}
widget.onFocus?.call(value);
},
child: buildInput(AntdRow(
style: style.rowStyle,
children: [
if (widget.prefix != null) widget.prefix!,
Expanded(
child: Stack(
alignment: buildAlignment(),
children: [
if (widget.placeholder != null)
ValueListenableBuilder(
valueListenable: innerController,
builder: (context, value, _) {
return AntdBox(
style: style.placeholderStyle,
child: value.text.isEmpty ? widget.placeholder! : null,
);
},
),
TextFieldTapRegion(
child: selectionGestureDetectorBuilder.buildGestureDetector(
behavior: HitTestBehavior.translucent, child: editText))
],
),
),
ValueListenableBuilder(
valueListenable: innerController,
builder: (context, value, _) {
if (widget.readOnly != true &&
widget.disabled != true &&
widget.clearable &&
!widget.obscureText) {
return Visibility(
visible: value.text.isNotEmpty,
maintainSize: true,
maintainAnimation: true,
maintainState: true,
child: AntdIconWrap(
style: style.clearIconStyle,
child: AntdBox(
options: const AntdTapOptions(alwaysReceiveTap: true),
onTap: () async {
innerController.clear();
},
child: style.clearIcon,
),
),
);
}
return const AntdBox();
}),
if (widget.obscureText && widget.obscureIcon)
AntdIconWrap(
style: _obscureText
? style.activeObscureIconStyle
: style.obscureIconStyle,
child: AntdBox(
options: const AntdTapOptions(alwaysReceiveTap: true),
onTap: () async {
setState(() {
_obscureText = !_obscureText;
});
},
child:
_obscureText ? style.activeObscureIcon : style.obscureIcon,
),
),
if (widget.suffix != null) widget.suffix!
],
)),
);
}