Home > OS >  Disabled space caused by validator in TextFormField
Disabled space caused by validator in TextFormField

Time:05-02

I got multiple TextFormField widgets. The problem is when the user doesn't meet some of the requirements while filling the form , some error message will pop under the TextFormField .

The problem is that the error text is causing too much space between the widgets.

How can I reduce the amount of that space ?

    TextFormField buildConformPassFormField() {
    return TextFormField(
      obscureText: true,
      onSaved: (newValue) => conform_password = newValue,
      onChanged: (value) {
        if (value.isNotEmpty) {
          removeError(error: kPassNullError);
        } else if (value.isNotEmpty && password == conform_password) {
          removeError(error: kMatchPassError);
        }
        conform_password = value;
      },
      validator: (value) {
        if (value!.isEmpty) {
          addError(error: kPassNullError);
          return ""; // THIS IS WHAT CAUSING THE WHITE SPACE.
        } else if ((password != value)) {
          addError(error: kMatchPassError);
          return ""; // THIS IS WHAT CAUSING THE WHITE SPACE.
        }
        return null;
      },
      decoration: InputDecoration(
        labelText: "Confirmez le mot de passe",
        hintText: "Re-entrez le mot de passe",
        // If  you are using latest version of flutter then lable text and hint text shown like this
        // if you r using flutter less then 1.20.* then maybe this is not working properly
        floatingLabelBehavior: FloatingLabelBehavior.always,
        suffixIcon: CustomSurffixIcon(svgIcon: "assets/icons/Lock.svg"),
      ),
    );
  }

CodePudding user response:

Just return null, remove all return ""; from the validator

CodePudding user response:

share screen shoot of current output when error show's. in general, try to add errorStyle: TextStyle(height: 0.7), to InputDecoration.

  • Related