Closed carman247 closed 3 years ago
Nope, ignore this .. I was setting state in the parent widget and it was updating the child
Nope, ignore this .. I was setting state in the parent widget and it was updating the child
@carman247 I do need to call setState()
because I'm storing in my widget state the result of onInputValidated()
in order to show custom validation messages.
How do you managed to solve this?
EDIT: If someone has the same problem, I have solved it using a "ValueListenableBuilder ()
":
/*class fields*/
ValueListenable<bool?> mobileIsValid;
[...]
/*build(...) method*/
ValueListenableBuilder<bool?>(
valueListenable: mobileIsValid,
child: InternationalPhoneNumberInput( /* Configuring the widget as child avoids reloading */
onInputChanged: (number) {
mobile = number;
},
onInputValidated: (valid) {
mobileIsValid.value = valid; /*Use here a ValueListenable instead of a setState() call*/
},
),
builder: (context, value, child) {
return CupertinoFormRow(
prefix: const Text("Móvil"),
error: value == null || value
? null
: const Text(
"Indica un número de móvil válido"),
child: child!);
}),
Hi,
This is a great package but it seems like once a number is validated using the
onInputValidated
function then that function runs continuously ... at least on Android it does.