重点关注TextFormField时如何隐藏错误出现 [英] How to hide error appearances when TextFormField is focused
问题描述
我将TextFormField
用于表单和自定义验证器方法以返回错误消息.
当文本字段聚焦时,我试图隐藏TextFormField
上的默认错误消息和错误边框.
I'm using TextFormField
for a form and custom validator method to return error message.
I'm trying to hide default error message and error border on the TextFormField
when the text field get focused.
TextFormField(
focusNode: _focusNode,
validator: widget.validator,
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue, width: 5.0),
borderRadius: BorderRadius.circular(5),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide(
color: const Color(0x1C707070),
width: 0.5,
),
)
我的问题是,当文本字段获得焦点时,错误边框将被覆盖.下划线变成红色.我知道这是TextFormField
的工作方式.
My problem is, the error border is overridden when the textfield get focused. And the underline turns red. I know this is how TextFormField
works.
但是我想要实现的是在文本字段获得焦点时隐藏所有错误外观,包括错误消息.
But what i'm trying to achieve is Hiding all error appearances including the Error message when the text field get focused.
推荐答案
我已经通过添加errorStyle
& focusedErrorBorder
.
I've achieved desired UI by adding errorStyle
& focusedErrorBorder
.
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue, width: 1.0),
),
errorStyle: _focusNode.hasFocus ? TextStyle(fontSize: 0, height: 0) : null,
focusedErrorBorder: UnderlineInputBorder(
borderSide: BorderSide.none,
),
这篇关于重点关注TextFormField时如何隐藏错误出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!