[英]Flutter - How to change the border color of the TextField?
我开始使用 flutter 学习,我想更改 TextField 的边框颜色,因为默认情况下它是灰色的,如屏幕截图所示:
我为我的应用程序使用黑色背景色,并且 TextField 的边框不可见,仅在聚焦或使用键盘时可见
我尝试过使用new Theme
:
Container(
child: new Theme(
data: ThemeData(
primaryColor: Colors.white,
//
inputDecorationTheme: InputDecorationTheme(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white))),
),
child: Column(
children: [
TextField(
style: TextStyle(
color: Colors.white,
),
decoration: InputDecoration(
labelText: 'EMAIL',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
],
),
)),
它看起来像这样:
Mush 更容易将应用程序主题模式设置为深色,并在您确定主题时使用默认 Theme.dark。 深色主题与文本字段等配合得很好。
Sravan Kumar Nerella 的回答很有帮助,我没有这样想过,但是我继续研究,我不知道可以为容器设置主题,这就是我的代码结果:希望它有帮助给别人
Container(
child: Theme(
data: new ThemeData.dark(), // HERE
child: Column(
children: [
TextField(
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: 'EMAIL',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.white,
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
),
),
],
),
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.