我有一个TextFormField
,它有一个返回字符串的验证器。我想以红色显示验证错误消息,并且可能是其他样式
代码
TextFormField(
textCapitalization: TextCapitalization.words,
decoration: InputDecoration(
border: UnderlineInputBorder(),
filled: true,
icon: Icon(Icons.person),
hintText: 'First name',
labelText: 'First Name *',
),
onSaved: (String value) {
this._customer.fName = value;
},
validator: _validateName,
initialValue: this._customer.fName,
),
答案 0 :(得分:0)
要在整个应用程序中更改错误颜色,请覆盖<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="card bg-light wow fadeIn position-relative">
<div class="row no-gutters">
<div class="col-md-12">
<div class="card-body">
<h4>Test</h4>
<p>Caption</p>
<a href=".." class="stretched-link"></a>
</div>
</div>
</div>
</div>
的{{1}}属性:
theme
答案 1 :(得分:0)
您可以直接在color
小部件上设置错误消息字体InputDecoration
和其他属性。这使您可以自定义每个TextFormField
小部件,使其具有不同的外观,例如color
,fontSize
,errorMaxLines
等。
TextFormField(
textCapitalization: TextCapitalization.words,
decoration: InputDecoration(
errorStyle: TextStyle(
color: Colors.red,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
errorMaxLines: 2,
border: UnderlineInputBorder(),
filled: true,
icon: Icon(Icons.person),
hintText: 'First name',
labelText: 'First Name *',
),
onSaved: (String value) {
this._customer.fName = value;
},
validator: _validateName,
initialValue: this._customer.fName,
),