how to remove error text below my textfield in flutter

Viewed 39

hey i am trying to remove the error this condition is working for me to remove the error but it does not change border color border color still remain same means border color remain red so how to change the border color to normal color

TextField(
                controller: userName,
                onChanged: (value){},
                decoration: InputDecoration(
                  hintText: "Email",
                  errorText: valid == true ? "" : "Not Good",
                  errorStyle: TextStyle(fontSize: valid == true ? 0 : 12),
                  prefixIcon: const Icon(Icons.email),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                    borderSide: BorderSide(color: valid == true ? Colors.black : Colors.red)
                  ),
                ),
              ),
2 Answers

There is a parameter called errorBorder in InputDecoration() you can use it to add custom border on error.

TextField(
 decoration: InputDecoration(         
            errorBorder: OutlineInputBorder(),),
)

did you use errorBorder

TextField(
  onChanged: (value) {},
  decoration: InputDecoration(
    errorBorder: const OutlineInputBorder(
      borderSide: BorderSide(color: Colors.red, width: 0.0),
    ),
    hintText: "Email",
    errorText: valid == true ? "email" : "Not Good",
    errorStyle: TextStyle(fontSize: valid == true ? 0 : 12),
    prefixIcon: const Icon(Icons.email),
    border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(10),
        borderSide:
            BorderSide(color: valid == true ? Colors.black : Colors.blue)),
  ),
);
Related