Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validatorMessage doesnt appear if is different of AutovalidateMode.always or doesnt triggered onChanged #405

Open
ViniciusLucas14 opened this issue Sep 18, 2023 · 0 comments

Comments

@ViniciusLucas14
Copy link

ViniciusLucas14 commented Sep 18, 2023

validatorMessage only appears if the field is touched, triggering onchange event or if AutovalidateMode.always is settled .

Package version
^3.2.0

Flutter version
Flutter 3.7.8

Steps to reproduce the behavior:

class UsuarioCadastro extends StatefulWidget {
  UsuarioCadastro({Key? key}) : super(key: key);
  @override
  _UsuarioCadastroState createState() => _UsuarioCadastroState();
}

class _UsuarioCadastroState extends State<UsuarioCadastro> {
  final _telefoneCliente = TextEditingController();
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          margin: EdgeInsets.only(
              left: MediaQuery.of(context).size.width / 6,
              right: MediaQuery.of(context).size.width / 6),
          child: Form(
              key: _formKey,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  IntlPhoneField(
                    controller: _telefoneCliente,
                    validator: (telefone) {
                      if (telefone == null || telefone.number.isEmpty)
                        return 'Campo obrigatório.';

                      return null;
                    },
                  ),
                  Expanded(
                    child: ElevatedButton(
                      child: Text('Cadastrar'),
                      onPressed: () {
                        if (_formKey.currentState!.validate()) {}
                      },
                    ),
                  ),
                ],
              )),
        ),
      ),
    );
  }

I expect validatorMessage appears when form is being validate, if we check validator in intl_phone_field, it's triggered when button is pressed but no message appears
if (value == null || !isNumeric(value)) return validatorMessage;
returns nothing
line 419 and 420

@ViniciusLucas14 ViniciusLucas14 changed the title validatorMessage doesnt appear if is not AutovalidateMode.always or doesnt triggered onChanged validatorMessage doesnt appear if is different of AutovalidateMode.always or doesnt triggered onChanged Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant