在FLUTTER中更改TextFormField的默认边框颜色

时间:2019-06-24 05:40:10

标签: flutter dart textfield default flutter-layout

当TextFormField不活动时,无法更改默认边框颜色。当TextFormField不处于活动状态时,它将显示DarkGrey-Border颜色。因此,如何更改它。

enter image description here

Theme(
              data: new ThemeData(
                primaryColor: Colors.red,
                primaryColorDark: Colors.black,
              ),
              child: TextFormField(
                decoration: new InputDecoration(
                  labelText: "Enter Email",
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(25.0),
                    borderSide: new BorderSide(),
                  ),
                  //fillColor: Colors.green
                ),
                validator: (val) {
                  if (val.length == 0) {
                    return "Email cannot be empty";
                  } else {
                    return null;
                  }
                },
                keyboardType: TextInputType.emailAddress,
                style: new TextStyle(
                  fontFamily: "Poppins",
                ),
              ),
            ),

1 个答案:

答案 0 :(得分:1)

使用enabledBorder中的InputDecoration,不要忘记也可以使用focusedBorder,如下所示:

InputDecoration(
                labelText: "Enter Email",
                fillColor: Colors.white,
                focusedBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(25.0),
                  borderSide: BorderSide(
                    color: Colors.blue,
                  ),
                ),
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(25.0),
                  borderSide: BorderSide(
                    color: Colors.red,
                    width: 2.0,
                  ),
                ),
)

您在这里有更多信息:https://api.flutter.dev/flutter/material/InputDecoration/enabledBorder.html