'flutter how to get OTP autofill in to otpController.text from firebase

flutter how to get OTP autofill into otpController.text from firebase --: when get OTP in mobile, need to auto-fills OTP in a text box, i am doing it in _onVerificationCompleted method.

_onVerificationCompleted(PhoneAuthCredential authCredential) async {

debugPrint("verification completed ${authCredential.smsCode}");
User? user = FirebaseAuth.instance.currentUser;
setState(() {
    // need otp so i can autofill in a textbox
otpController.text = authCredential.smsCode!;
});
if (authCredential.smsCode != null) {
try {
    UserCredential credential =
    await user!.linkWithCredential(authCredential);
} on FirebaseAuthException catch (e) {
    if (e.code == 'provider-already-linked') {
    await auth.signInWithCredential(authCredential);
    }
}

}
}
Future<void> sendOtp() async {

print(numController.text);
await auth.verifyPhoneNumber(

phoneNumber: "+91" + numController.text,

verificationCompleted: _onVerificationCompleted,

verificationFailed: (FirebaseAuthException e) {
    if (e.code == 'invalid-phone-number') {
    print('The provided phone number is not valid.');
    }
},

codeSent: (String verificationId, int? resendToken) async {
    this.verificationId = verificationId;
    signature = await SmsAutoFill().getAppSignature;
    print("app signature");
    print(signature);
    setState(() {
    visibleValMobile = false;
    visibleValOtp = true;
    sendOtpMobile = "We Have Send OTP On " + numController.text;
    });

},

codeAutoRetrievalTimeout: (String verificationId) {
    print('codeAutoRetrievalTimeout');
},
);
}

flutter when get OTP in mobile, it auto-fills a text box



Solution 1:[1]

There are plenty of options like otp_autofill, alt_sms_autofill and sms_autofill

For the alt_sms_autofill example, https://stackoverflow.com/a/70076071/4639894

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 suzan