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

标签 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",
                ),
              ),
            ),

最佳答案

使用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

关于flutter - 更改FLUTTER中TextFormField的默认边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56730412/

相关文章:

canvas - 为什么不赞成使用context2d.backingStorePixelRatio?

flutter - 如何使用提供程序作为状态管理从列表中正确设置选定的小部件?

dart - 为什么 Dart 的 Datetime.parse 不是工厂构造函数?

json - 如何在Dart中创建特定类型的嵌套JSON数据?

android - AndroidManifest.xml :5:9-42 requires a placeholder substitution but no value for <applicationName> is provided. 中的属性 application@name - Flutter

dart - Flutter: 'NoSuchMethodError' 不是 String 类型的子类型

asynchronous - 异步对调用者滚雪球,不能使构造函数异步

ios - 在 View Controller 之间传递数据 - iOS Xcode - 什么是好方法?

ios - 如何以编程方式禁用预测 View 但在 iOS 中的 TextView 上启用自动更正?

cocoa - 将文本字段绑定(bind)到共享用户默认 Controller 不使用空值