Change the default border color of TextFormField in FLUTTER

jazzbpn picture jazzbpn · Jun 24, 2019 · Viewed 12.6k times · Source

Unable to change the default border color when TextFormField is not active. When TextFormField is not active this shows DarkGrey-Border color. So, how to change that.

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

Answer

diegoveloper picture diegoveloper · Jun 24, 2019

Use enabledBorder of the InputDecoration, don't forget you can also use the focusedBorder, like this :

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,
                  ),
                ),
)

Here you have more info: https://api.flutter.dev/flutter/material/InputDecoration/enabledBorder.html