TfTextField class
单个输入框。
这个组件不做校验,需要自己传入 errorText。在表单里需要校验时,
请改用 TfTextFormField;输入密码请用 TfPasswordField。
设置 suffixIcon 和 onSuffixTap 可以在右侧放一个可点击的图标, 例如“清空”;suffixTooltip 是它的提示文字。
final _search = TextEditingController();
TfTextField(
controller: _search,
placeholder: '搜索',
prefixIcon: Icons.search,
suffixIcon: Icons.clear,
suffixTooltip: '清空',
onSuffixTap: _search.clear,
textInputAction: TextInputAction.search,
onSubmitted: runSearch,
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- TfTextField
Constructors
-
TfTextField({Key? key, TextEditingController? controller, FocusNode? focusNode, String? placeholder, IconData? prefixIcon, IconData? suffixIcon, String? suffixTooltip, VoidCallback? onSuffixTap, String? errorText, bool obscureText = false, bool enabled = true, int maxLines = 1, TextInputType? keyboardType, TextInputAction? textInputAction, Iterable<
String> ? autofillHints, ValueChanged<String> ? onChanged, ValueChanged<String> ? onSubmitted}) -
const
Properties
-
autofillHints
→ Iterable<
String> ? -
自动填充提示,例如
[AutofillHints.email],让系统填入已保存的账号密码。final - controller → TextEditingController?
-
用于读写输入内容;由调用方创建并负责
dispose。final - enabled → bool
-
为 false 时禁止输入。
final
- errorText → String?
-
不为 null 时输入框显示为错误状态,并在下方显示这段文字。
final
- focusNode → FocusNode?
-
用于控制焦点(可选)。
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- keyboardType → TextInputType?
-
键盘类型,例如
TextInputType.emailAddress。final - maxLines → int
-
最多显示的行数;大于 1 时可输入多行。
final
- obscureText → bool
-
为 true 时以圆点隐藏输入内容。
final
-
onChanged
→ ValueChanged<
String> ? -
每次输入变化时回调。
final
-
onSubmitted
→ ValueChanged<
String> ? -
按下键盘回车时回调。
final
- onSuffixTap → VoidCallback?
-
点击右侧图标时回调。
final
- placeholder → String?
-
占位提示。Material 3 下会显示为浮动标签。
final
- prefixIcon → IconData?
-
左侧图标(可选)。
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- suffixIcon → IconData?
-
右侧可点击图标(可选)。
final
- suffixTooltip → String?
-
右侧图标的提示和无障碍标签。
final
- textInputAction → TextInputAction?
-
键盘回车键的动作,例如“下一项”“完成”。
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited