焦点上的 Flutter 文本字段背景颜色
Flutter textfield background color on focus
我有一个圆形的文本字段。它运行良好,但是当用户点击它时,会出现灰色背景。我怎样才能禁用飞溅效果?
这是我的代码和结果:
new Container(
margin: const EdgeInsets.only(left: 30.0, top: 60.0, right:
30.0),
height: 40.0,
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.all(new Radius.circular(25.7))
),
child: new Directionality(
textDirection: TextDirection.ltr,
child: new TextField(
controller: null,
autofocus: false,
style:
new TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding: const EdgeInsets.only(
left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
),
))),
看起来是文本框的飞溅效果造成的。我找不到针对该特定小部件禁用它的方法,但您可以通过将 TextField
包装在 Theme
小部件并将 splashColor
设置为透明来使其透明:
Theme(
data: Theme.of(context).copyWith(splashColor: Colors.transparent),
child: TextField(
autofocus: false,
style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
),
),
);
使用BorderSide.none作为:
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide.none,
),
“Flutter Textfield 背景颜色”
*在 flutter 中更改 TextField 的边框颜色
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
focusedBorder:OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(25.0),
),
),
)
文本字段颜色抖动
TextField(
style: TextStyle(color: Colors.red),
decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)
Flutter TextFormField 背景颜色
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
filled: true, // dont forget this line
...
)
...
)
Flutter 文本字段标签颜色
labelStyle: TextStyle(
color: Colors.white,
)
彩色文本框文字抖动
TextField(
style: TextStyle(color: Colors.white),
...
)
我有一个圆形的文本字段。它运行良好,但是当用户点击它时,会出现灰色背景。我怎样才能禁用飞溅效果?
这是我的代码和结果:
new Container(
margin: const EdgeInsets.only(left: 30.0, top: 60.0, right:
30.0),
height: 40.0,
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.all(new Radius.circular(25.7))
),
child: new Directionality(
textDirection: TextDirection.ltr,
child: new TextField(
controller: null,
autofocus: false,
style:
new TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding: const EdgeInsets.only(
left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: new BorderSide(color: Colors.white),
borderRadius: new BorderRadius.circular(25.7),
),
),
))),
看起来是文本框的飞溅效果造成的。我找不到针对该特定小部件禁用它的方法,但您可以通过将 TextField
包装在 Theme
小部件并将 splashColor
设置为透明来使其透明:
Theme(
data: Theme.of(context).copyWith(splashColor: Colors.transparent),
child: TextField(
autofocus: false,
style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Username',
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 8.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(25.7),
),
),
),
);
使用BorderSide.none作为:
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide.none,
),
“Flutter Textfield 背景颜色”
*在 flutter 中更改 TextField 的边框颜色
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
focusedBorder:OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(25.0),
),
),
)
文本字段颜色抖动
TextField(
style: TextStyle(color: Colors.red),
decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)
Flutter TextFormField 背景颜色
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
filled: true, // dont forget this line
...
)
...
)
Flutter 文本字段标签颜色
labelStyle: TextStyle(
color: Colors.white,
)
彩色文本框文字抖动
TextField(
style: TextStyle(color: Colors.white),
...
)