聚焦 TextFormField 时如何隐藏错误出现 [英] How to hide error appearances when TextFormField is focused

查看:11
本文介绍了聚焦 TextFormField 时如何隐藏错误出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆