当 Textformfield 处于非活动状态、活动状态和已填充状态时具有不同的边框颜色
当字段不活动时,当活动且不活跃时,在flutter中的每个状态都有不同的边框颜色,但在字段中具有文本
TextFormField emailUserForm() {
return TextFormField(
keyboardType: TextInputType.emailAddress,
cursorColor: textBlack50Color,
autocorrect: false,
validator: (text) => validateEmail(text!),
onSaved: (name) {
_email = name!;
print('on save called');
},
decoration: const InputDecoration(
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide(color: textBlack50Color, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
labelStyle: TextStyle(
color: textBlack50Color,
fontSize: 14,
fontWeight: FontWeight.w500),
hintStyle: TextStyle(fontSize: 17),
hintText: 'Your email address',
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: textBlackColor, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: textBlackColor , width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
),
);
}
Is is possible to have a different border color for each state of the TextFormField in flutter ie when the field is not active , when active and not active but has text in the field
TextFormField emailUserForm() {
return TextFormField(
keyboardType: TextInputType.emailAddress,
cursorColor: textBlack50Color,
autocorrect: false,
validator: (text) => validateEmail(text!),
onSaved: (name) {
_email = name!;
print('on save called');
},
decoration: const InputDecoration(
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide(color: textBlack50Color, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
labelStyle: TextStyle(
color: textBlack50Color,
fontSize: 14,
fontWeight: FontWeight.w500),
hintStyle: TextStyle(fontSize: 17),
hintText: 'Your email address',
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: textBlackColor, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: textBlackColor , width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
),
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您应该在
InputDecoration
类中设置特定属性。根据文档,以下是不同的边框样式:代码:
Yes, you should set the specific properties inside the
InputDecoration
class. Based on the documentation, here are the different border styles:Code:
尝试下面的代码希望对您有帮助。
没有对焦屏幕的结果->
焦点屏幕的结果 ->
Try below code hope its help to you.
Your result without focus screen->
Your result with focus screen->
您可以设置
控制器
,并在enabledborder
属性中尝试一些内容。使用AnimatedBuilder
来收听文本输入更改。You can set a
controller
and try something in theenabledBorder
property. UseAnimatedBuilder
to listen to text input changes.