当 TextFormField 未激活时无法更改默认边框颜色。当 TextFormField 未激活时,将显示 DarkGrey-Border 颜色。那么,如何改变这一点。
Theme(
data: new ThemeData(
primaryColor: Colors.red,
primaryColorDark: Colors.black,
),
child: TextFormField(
decoration: new InputDecoration(
labelText: "Enter Email",
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Email cannot be empty";
} else {
return null;
}
},
keyboardType: TextInputType.emailAddress,
style: new TextStyle(
fontFamily: "Poppins",
),
),
),
最佳答案
使用InputDecoration
的enabledBorder
,不要忘记您还可以使用focusedBorder
,如下所示:
InputDecoration(
labelText: "Enter Email",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.red,
width: 2.0,
),
),
)
这里有更多信息:https://api.flutter.dev/flutter/material/InputDecoration/enabledBorder.html
关于flutter - 更改FLUTTER中TextFormField的默认边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56730412/