natintosh / intl_phone_number_input

MIT License
163 stars 490 forks source link

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

Open ViniciusLucas14 opened 11 months ago

ViniciusLucas14 commented 11 months ago

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