请参见下面的更新或@ GJJ2019的答案
刚使用过:
decoration: InputDecoration(enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.cyan), ), focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.cyan), ), ),
这个对我有用 :)
逻辑答案是使用InputBorder,尤其是UnderlineInputDecorator,并将其作为边框传递给inputdecorator。但是,所有这些操作都告诉InputDecorator是应该使用下划线还是其他指定的内容。
实际颜色基于主题-来源:
Color _getActiveColor(ThemeData themeData) { if (isFocused) { switch (themeData.brightness) { case Brightness.dark: return themeData.accentColor; case Brightness.light: return themeData.primaryColor; } } return themeData.hintColor;}因此,要更改颜色,请执行以下操作(或为整个应用程序指定主题):
new Theme( data: new ThemeData( primaryColor: Colors.red, accentColor: Colors.orange, hintColor: Colors.green ), child: new TextField( decoration: new InputDecoration( hintText: "Enter your email", labelText: "Email", labelStyle: new TextStyle(color: const Color(0xFF424242)), border: new UnderlineInputBorder( borderSide: new BorderSide( color: Colors.red ) ) ), ),),
更新:
现在可以按照您 期望 的方式进行操作。
decoration: InputDecoration( enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: theColor), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: theColor), ), border: UnderlineInputBorder( borderSide: BorderSide(color: theColor), ),)



