Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

shaikhaman2000
Copy link

No description provided.

lib/otp_field.dart Outdated Show resolved Hide resolved
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
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
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
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
Author

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

@shaikhaman2000
Copy link
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