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

deyfvvtc  于 2023-02-05  发布在  Flutter
关注(0)|答案(2)|浏览(276)

当TextFormField不活动时,无法更改默认边框颜色。当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",
                ),
              ),
            ),
fhg3lkii

fhg3lkii1#

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

js5cn81o

js5cn81o2#

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

相关问题