我有一个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,
),Run Code Online (Sandbox Code Playgroud)
编辑1:
我在 ThemeData 中添加了以下内容。
final ThemeData myTheme = ThemeData(
errorStyle: TextStyle(
color: Colors.red,
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
errorColor: Color(0xffd32f2f),
)
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lead Manager',
theme: myTheme,
home: Home(),
);
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
小智 8
你可以像这样设置 errorText 的样式。
TextFormField(
textCapitalization: TextCapitalization.words,
decoration: InputDecoration(
border: UnderlineInputBorder(),
filled: true,
icon: Icon(Icons.person),
hintText: 'First name',
labelText: 'First Name *',
//textError styling
errorStyle: TextStyle(color: Colors.teal)),
onSaved: (String value) {
this._customer.fName = value;
},
validator: _validateName,
initialValue: this._customer.fName,
);
Run Code Online (Sandbox Code Playgroud)
更多细节在这里errorStyle 属性。
TextFields要更改整个应用程序的错误颜色和其他可能的错误消息,请在MaterialApp声明中添加 theme 属性并覆盖errorColor:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: Home(),
// Add this line
theme: ThemeData(errorColor: Colors.yellow),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4594 次 |
| 最近记录: |