如何禁用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
相关产品推荐
相关产品推荐

