How to hide error appearances when TextFormField is focused

微笑、不失礼 提交于 2020-05-30 07:56:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!