繁体   English   中英

flutter 如何从 firebase 获取 OTP 自动填充到 otpController.text

[英]flutter how to get OTP autofill in to otpController.text from firebase

flutter 如何从 firebase 获取 OTP 自动填充到 otpController.text 中——:在移动设备中获取 OTP 时,需要在文本框中自动填充 OTP,我在 _onVerificationCompleted 方法中执行此操作。

_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 在移动设备中获取 OTP 时,它会自动填充一个文本框

有很多选项,例如otp_autofillalt_sms_autofillsms_autofill

对于 alt_sms_autofill 示例, https://stackoverflow.com/a/70076071/4639894

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM