如何更改焦点上的Flutter文本字段边框颜色

Nic*_*leZ 3 flutter flutter-layout

我使用输入装饰和Outlineboraderinput创建了一个简单的文本字段。在该文本字段上键入内容时,我想更改边框颜色。在下面的链接中,您可以看到我的作品。我想要的是将蓝色边框更改为白色

图片

TextFormField(
        decoration: InputDecoration(
          labelText: "Resevior Name",
          fillColor: Colors.white,
          enabledBorder:OutlineInputBorder(
            borderSide: const BorderSide(color: Colors.white, width: 2.0),
            borderRadius: BorderRadius.circular(25.0),
          ),
        ),
      )
Run Code Online (Sandbox Code Playgroud)

Nea*_*arl 11

In Flutter 2.5, you can change the focus color of the TextField directly in the ThemeData:

theme: ThemeData().copyWith(
  // change the focus border color of the TextField
  colorScheme: ThemeData().colorScheme.copyWith(primary: Colors.amber),
  // change the focus border color when the errorText is set
  errorColor: Colors.purple,
),
Run Code Online (Sandbox Code Playgroud)

Live Demo


all*_*ria 6

添加由enabledBorder插入的focusBorder

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),
          ),
        ),
      )
Run Code Online (Sandbox Code Playgroud)

  • 代码本身是非常不言自明的 (20认同)