【发布时间】:2020-09-12 15:09:28
【问题描述】:
我有一个 TextFormField 来收集用户认证输入,这很好。
但是当它显示验证消息时,会发生这种情况:
如何将错误消息的位置更改为不再发生?我只是想要一种方法来轻松解决这个问题,并且该领域仍然很漂亮。 这是代码。
Form(
key: _formKey,
child: Container(
width: double.infinity,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 1.1,
color: Colors.black45,
spreadRadius: 0.5,
offset: Offset(
1.5,
2,
),
),
],
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: SizedBox(
height: 40,
child: TextFormField(
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
border: InputBorder.none,
disabledBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
focusedBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
hintText: 'Full name',
hintStyle: TextStyle(color: Colors.grey[600]),
icon: Icon(Icons.account_circle, color: Colors.black),
),
onSaved: (string) => _formData['name'] = string,
validator: (string) {
if (string.isEmpty) {
return 'Field can\'t be empty';
}
return null;
},
),
),
),
),
)
【问题讨论】:
-
这不是负责文本字段的代码,您将此文本字段作为材料或容器的子项?
-
@AmanVerma 是的,我是。