-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: master
Are you sure you want to change the base?
Conversation
lib/otp_field.dart
Outdated
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; | ||
}); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this 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.
I will be pushing the changes you suggested above. Thank you. |
@iamvivekkaushik Have a look |
No description provided.