Flutter_Pinput
Flutter_Pinput copied to clipboard
onCompleted returns pin longer than specified length
length: 6,
onCompleted: (String pin) async {
print(pin);
}
Here print(pin); sometimes prints a String that is longer than 6 digits in length.
I am temporarily using pin.substring(0,6) to prevent errors when using input with firebase phone auth.
Hi @da-revo, are you using the latest version?
Yes.
pinput: ^2.2.7
/// in pinput_state.dart
void _onChanged(String pin) {
widget.onChanged?.call(pin);
if (_completed) {
widget.onCompleted?.call(pin); /// changing pin to pin.substring(0,widget.length) here could work
_maybeValidateForm();
_maybeCloseKeyboard();
}
}
This error can be replicated by inputting more characters than specified in the length property, quickly.
/// in pinput_state.dart void _onChanged(String pin) { widget.onChanged?.call(pin); if (_completed) { widget.onCompleted?.call(pin); /// changing pin to pin.substring(0,widget.length) here could work _maybeValidateForm(); _maybeCloseKeyboard(); } }
_completed checks the length, on top of that I can't reproduce the issue. Weird.
https://github.com/Tkko/Flutter_Pinput/blob/60026e37727df5390bca381313999a612d89d543/lib/src/pinput_state.dart#L64
Since pin is just the text in the controller, it can be changed while onCompleted is called asynchronously. That could be the cause.
@da-revo Which Flutter version are you using?
Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-arm, locale en-IN)
Sorry for the late reply, I'm not able to reproduce the issue thus closing this issue, feel free to reopen it if you need to.