问题
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,
),
)
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.
回答1:
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,
),
来源:https://stackoverflow.com/questions/61317449/how-to-hide-error-appearances-when-textformfield-is-focused