setFocus method

void setFocus(
  1. int position
)

Implementation

void setFocus(int position) {
  final maxIndex = _otpTextFieldState.widget.length - 1;
  if (position > maxIndex) {
    throw Exception(
        "Provided position is out of bounds for the OtpTextField");
  }

  final focusNodes = _otpTextFieldState._focusNodes;
  final focusNode = focusNodes[position];

  if (focusNode != null) {
    focusNode.requestFocus();
  }
}