traverse method
Handles the traversal of the OTP items when the user presses the left or right arrow key.
Implementation
void traverse({required bool forward}) {
/// The default traversal collapses to the start/end of the selection range. We instead move to the previous/next
/// item outside it.
if (selection.isCollapsed) {
final adjustment = (forward ? 1 : -1);
value = value.copyWith(selection: .collapsed(offset: (selection.baseOffset + adjustment).clamp(0, text.length)));
} else {
final offset = forward ? selection.end : max(selection.start - 1, 0);
value = value.copyWith(selection: .collapsed(offset: offset));
}
}