如何在flutter中更改textField的下划线颜色?

ven*_*pta 8 flutter flutter-layout

我试图定义Input装饰来更改输入TextField下划线的颜色。但这不起作用。有人可以建议我在这里想念什么吗?

这是代码段:

decoration: InputDecoration(
    hintText: 'Username',
    hintStyle: TextStyle(color: Colors.white),
    border: new UnderlineInputBorder(
                                    borderSide: BorderSide(color: Colors.white, 
                                      width: 1.0, style: BorderStyle.none ),
    ),
Run Code Online (Sandbox Code Playgroud)

小智 7

decoration: InputDecoration(
  hintText: 'Username',
  hintStyle: TextStyle(color: Colors.white),
  enabledBorder: new UnderlineInputBorder(
    borderSide: BorderSide(
      color: Colors.white, 
      width: 1.0, 
      style: BorderStyle.none 
    ),
  ),
),
Run Code Online (Sandbox Code Playgroud)

只需将边框更改为即可enabledBorder。希望有帮助!


jit*_*555 6

我们必须同时使用enabledBorderfocusedBorder

  • enabledBorder:TextField没有焦点时它会起作用。
  • focusedBorder:TextField有焦点时它会起作用。
enabledBorder: new UnderlineInputBorder(
  borderSide: BorderSide(
    color: Colors.black
  ),
),
// and:
focusedBorder: new UnderlineInputBorder(
  borderSide: BorderSide(
    color: Colors.black
  ),
),
Run Code Online (Sandbox Code Playgroud)


Sun*_*nil 2

您必须将小部件层次结构放在MaterialApp下。

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: 'Flutter WebView Demo',
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
          home: new Container(
             **//put widget here.**
        ));
  }
}
Run Code Online (Sandbox Code Playgroud)