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

Autofocus Issue #13

Open
BlackGold-1989 opened this issue Apr 28, 2021 · 6 comments
Open

Autofocus Issue #13

BlackGold-1989 opened this issue Apr 28, 2021 · 6 comments

Comments

@BlackGold-1989
Copy link

I can't set otp text field to autofocus.

@devsideal
Copy link

Yes, I'm also facing the same issue, It's not supporting focusNode.

@manukumarsb7
Copy link

I'm also facing the same issue

@annpinchuk
Copy link

annpinchuk commented Jan 18, 2022

same

@iamvivekkaushik
Copy link
Owner

You can use the OtpFieldController to set focus on any text field.

@hasancse91
Copy link

You can use the OtpFieldController to set focus on any text field.

Could you please describe a little bit the use of OtpFieldController?

I've tried to use in this way (given below). and found error LateInitializationError: Field _otpTextFiledState@1709191556 ....

Widget _getOtpView(Size screenSize, ProfileController controller) {
    var otpFieldController = OtpFieldController();
    otpFieldController.setFocus(1);

    return OTPTextField(
      otpFieldStyle: OtpFieldStyle(borderColor: otpPlaceholderColor),
      length: 5,
      width: screenSize.width - 80,
      fieldWidth: 50,
      style: TextStyle(fontSize: 17, color: profileBlack),
      textFieldAlignment: MainAxisAlignment.spaceAround,
      fieldStyle: FieldStyle.underline,
      onCompleted: controller.verifyOtp,
      controller: otpFieldController,
    );
  }

@KLD
Copy link

KLD commented Oct 6, 2022

Try this:

  final controller = OtpFieldController();

  @override
  void initState() {
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      controller.setFocus(0);
    });
  }

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

No branches or pull requests

7 participants