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

The method 'saveAndValidate' was called on null. #174

Closed
irwinOT opened this issue Nov 13, 2019 · 3 comments
Closed

The method 'saveAndValidate' was called on null. #174

irwinOT opened this issue Nov 13, 2019 · 3 comments

Comments

@irwinOT
Copy link

irwinOT commented Nov 13, 2019

showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return AlertDialog(
actions: [
MaterialButton(
child: Text("Guardar"),
onPressed: () {
if (_formKey.currentState.saveAndValidate()) {
Navigator.pop(context);
print(_formKey.currentState.value );
}
},
),
MaterialButton(
child: Text("Cancelar"),
onPressed: () {
Navigator.pop(context);
_auth.signOut();
},
),
],
content:
FormBuilder(
initialValue: {
'accept_terms': true,
},
key: _formKey,
autovalidate: true,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
FormBuilderTextField(
attribute: "name",
decoration: InputDecoration(labelText: "Nombre"),
validators: [
FormBuilderValidators.required(),
FormBuilderValidators.minLength(5),
],
),
FormBuilderTextField(
attribute: "cedula",
decoration:
InputDecoration(labelText: "No. Cédula"),
keyboardType: TextInputType.number,
validators: [
FormBuilderValidators.required(
errorText: "Ingrese la cédula (10 números)",
),
FormBuilderValidators.minLength(10,
errorText: "Debe contener 10 dígitos."),
FormBuilderValidators.maxLength(10,
errorText: "Debe contener 10 dígitos."),
],
),
FormBuilderTextField(
attribute: "phone",
decoration: InputDecoration(
labelText: "Celular", hintText: "0996123456"),
keyboardType: TextInputType.number,
validators: [
FormBuilderValidators.required(),
FormBuilderValidators.numeric(
errorText:
"Ingrese un número celular sin letras."),
FormBuilderValidators.minLength(10,
errorText: "Debe contener 10 dígitos."),
FormBuilderValidators.maxLength(10,
errorText: "Debe contener 10 dígitos."),
],
),
FormBuilderDropdown(
attribute: "gender",
decoration: InputDecoration(labelText: "Género"),
// initialValue: 'Male',
hint: Text('Seleccione género'),
validators: [FormBuilderValidators.required()],
items: ['Masculino', 'Femenino', 'Otro']
.map((gender) => DropdownMenuItem(
value: gender, child: Text("$gender")))
.toList(),
),
FormBuilderCheckbox(
attribute: 'accept_terms',
label: Text("Acepto términos y condiciones."),
validators: [
FormBuilderValidators.requiredTrue(
errorText:
"Usted debe aceptar términos y condiciones de uso para continuar.",
),
],
),
],
),
),
),
);
});

@danvick
Copy link
Collaborator

danvick commented Nov 14, 2019

Make sure you've declared and initialized your _formKey as shown in the example

@irwinOT
Copy link
Author

irwinOT commented Nov 14, 2019

Make sure you've declared and initialized your _formKey as shown in the example

already declared: final _formKey = GlobalKey();

@danvick
Copy link
Collaborator

danvick commented Nov 17, 2019

I've failed to reproduce your error. If you haven't already solved this, kindly share more of your code - preferably formatted for us to be able to assist easily

@danvick danvick added the awaiting author response Waiting for author of issue to respond with more info label May 7, 2020
@danvick danvick closed this as completed May 15, 2020
@deandreamatias deandreamatias removed the awaiting author response Waiting for author of issue to respond with more info label Jun 24, 2022
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

3 participants