You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Flutter中TextFormField点击时的边框样式变化?

解决Flutter TextFormField点击时边框不变蓝色的问题

当前效果

  • 点击时的效果:
    点击时的效果
  • 未点击时的效果:
    未点击时的效果

你需要让TextFormField在点击聚焦时,边框保持黑色而不是默认的蓝色,只需在InputDecoration中添加focusedBorder属性,设置和默认border完全一致的样式即可覆盖系统默认的聚焦态边框。

修改后的完整代码如下:

TextFormField(
  controller: searchPatient,
  decoration: InputDecoration(
    suffixIcon: InkWell(
      onTap: () => {
        setState(() {
          _getAppointmentList(searchPatient.text, selectedStatus, 0);
        })
      },
      child: Container(
        height: 25,
        color: Color.fromRGBO(14, 113, 176, 1),
        child: AspectRatio(
          aspectRatio: 2 / 1,
          child: Center(
            child: Icon(Icons.search, color: Colors.white),
          ),
        ),
      ),
    ),
    hintText: 'Search Patient Name, MRN ID.',
    hintStyle: TextStyle(color: Colors.grey, fontSize: 16),
    contentPadding: EdgeInsets.symmetric(horizontal: 15),
    border: OutlineInputBorder(
      borderSide: BorderSide(width: 1, color: Colors.black),
    ),
    // 新增:设置聚焦时的边框样式与默认状态一致
    focusedBorder: OutlineInputBorder(
      borderSide: BorderSide(width: 1, color: Colors.black),
    ),
  ),
)

这样设置后,输入框无论是否处于点击聚焦状态,边框都会保持你定义的黑色样式,不会切换到系统默认的蓝色边框。

内容的提问来源于stack exchange,提问作者John Reaper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 17:33:25