Flutter_Pinput icon indicating copy to clipboard operation
Flutter_Pinput copied to clipboard

onCompleted returns pin longer than specified length

Open da-revo opened this issue 3 years ago • 8 comments

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.

da-revo avatar May 07 '22 10:05 da-revo

Hi @da-revo, are you using the latest version?

Tkko avatar May 07 '22 11:05 Tkko

Yes. pinput: ^2.2.7

da-revo avatar May 07 '22 11:05 da-revo

/// 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();
    }
  }

da-revo avatar May 07 '22 11:05 da-revo

This error can be replicated by inputting more characters than specified in the length property, quickly.

da-revo avatar May 07 '22 11:05 da-revo

/// 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

Tkko avatar May 07 '22 12:05 Tkko

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 avatar May 07 '22 12:05 da-revo

@da-revo Which Flutter version are you using?

Tkko avatar May 07 '22 12:05 Tkko

Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-arm, locale en-IN)

da-revo avatar May 14 '22 09:05 da-revo

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.

Tkko avatar Oct 03 '22 17:10 Tkko