setValue method

void setValue(
  1. String value,
  2. int position
)

Implementation

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

  final textControllers = _otpTextFieldState._textControllers;
  final textController = textControllers[position];
  final currentPin = _otpTextFieldState._pin;

  if (textController != null) {
    textController.text = value;
    currentPin[position] = value;
  }

  String newPin = "";
  currentPin.forEach((item) {
    newPin += item;
  });

  final widget = _otpTextFieldState.widget;
  if (widget.onChanged != null) {
    widget.onChanged!(newPin);
  }
}