Skip to content

Made otp field text single digit and override text behaviour added#31

Open
shaikhaman2000 wants to merge 8 commits into
iamvivekkaushik:masterfrom
shaikhaman2000:updates
Open

Made otp field text single digit and override text behaviour added#31
shaikhaman2000 wants to merge 8 commits into
iamvivekkaushik:masterfrom
shaikhaman2000:updates

Conversation

@shaikhaman2000
Copy link
Copy Markdown

No description provided.

Comment thread example/lib/main.dart Outdated
Comment thread example/lib/main.dart Outdated
Comment thread lib/otp_field.dart Outdated
Comment thread lib/otp_field.dart
Comment on lines +215 to +230
if (str.length == widget.length && index == widget.length - 1) {
print('Handling Paste');
_handlePaste(str);
return;
} else {
if (_pin.length >= index + 1) {
str = str.replaceFirst(_pin[index], '');
} else {
int len = str.length;
str = str[len - 1];
}
// Update the current pin
setState(() {
_textControllers[index]!.text = str;
});
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why is this code here and not inside _handlePaste

Copy link
Copy Markdown
Author

@shaikhaman2000 shaikhaman2000 Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The previous behaviour was not allowing users to override previous individual otp field. What I did here is basically made the field length to 2.
  • When users want to paste otp they need to be on the initial field only and the text length should be equal to otp field length (Line number 215)
  • if the length is less than or equal to 2, we assume user wants to override previously written text -> We remove replace previous digit from this text and set the text to newly written text (In case of previously its being 2, and user writes 0 -> we replace 2 with '' and set text as 0)
  • if the same individual otp field doesn’t contain any text (i.e., user is typing first time) we handle it with line number 222's else block.
  • I have added onTap() function to make sure, user stays in the end of otp field to handle back press efficiently. (Previously when the user's cursor was pointing before text, it didn’t allowed erasing the text and wasn’t taking back to previously available field)

Copy link
Copy Markdown
Owner

@iamvivekkaushik iamvivekkaushik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not merging this, left comments.

@shaikhaman2000
Copy link
Copy Markdown
Author

I will be pushing the changes you suggested above. Thank you.

@shaikhaman2000
Copy link
Copy Markdown
Author

@iamvivekkaushik Have a look

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

Successfully merging this pull request may close these issues.

2 participants