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

56

当TextFormField未激活时,无法更改默认边框颜色。此时显示的是暗灰色边框颜色。那么,如何更改呢。

图片描述

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",
                ),
              ),
            ),
2个回答

149

使用InputDecorationenabledBorder属性,不要忘记还可以使用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


0
    OutlineInputBorder(
                    borderSide: BorderSide(
                    color: AppColor.secondaryBackground)),
                    focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(color: 
                    AppColor.secondaryBackground)),
                    enabledBorder: OutlineInputBorder(
                    borderSide:  BorderSide(color: 
                    AppColor.secondaryBackground),
    ),

你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接