pin_code_fields icon indicating copy to clipboard operation
pin_code_fields copied to clipboard

Input Formatter not applied when showing paste dialog

Open quaaantumdev opened this issue 9 months ago • 2 comments

The PinCodeTextField allows you to provide inputFormatters, but the paste process ingores these. I created a pull request to solve this: https://github.com/adar2378/pin_code_fields/pull/401 (changes should be non-breaking)

Let's say you only allow numbers and you have 6 digits:

PinCodeTextField(
  length: 6,
  keyboardType: TextInputType.number,
  inputFormatters: [
    FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
  ],
  // ...
)

Now try to paste the following plain text content on android: "123 456" (note the whitespace in between).

A user would most expect this to paste as "123456" but what actually gets inserted is "123 45". These are exactly 6 characters but as the inputFormatters are ignored, a whitespace gets pasted, the digits "45" end up in the wrong place and the last digit "6" is omitted as there is no space left for it.

I also found other issues and fixed them in the pull request as they are tightly related:

  • the file was broken exactly at place where i did the edits, something with the braces was messed up, looks like a previous merge corrupted it, is now fix
  • paste previously differed if you enabled/disabled showPasteConfirmationDialog as _showPasteDialog trimmed the content while _paste did not
  • there was no way to disable the trim when pasting, so if somebody really needs whitespace (e.g. pasting some kind of obsucre password), pasting did not work for them.

quaaantumdev avatar Apr 08 '25 10:04 quaaantumdev

Is this library reliable? I see no one has maintained it for two years.

yanashenyang avatar May 20 '25 03:05 yanashenyang

@adar2378 please merge this https://github.com/adar2378/pin_code_fields/pull/401

quaaantumdev avatar May 23 '25 07:05 quaaantumdev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 25 '25 06:07 stale[bot]