gpt4 book ai didi

flutter - 在Flutter中重新发送OTP代码Firebase电话身份验证

转载 作者:行者123 更新时间:2023-12-03 03:22:58 25 4
gpt4 key购买 nike

这可能是重复的,但任何其他线程都没有为我提供适当的答案。

有关于android本地语言的答案,但没有关于Flutter(dart)的答案。

我有以下可行的方法,但是如果我想向用户电话号码重新发送OTP,我该怎么做?只是一个简单的示例代码可能会有所帮助。

  Future signInWithPhone(String phone, BuildContext context) async {

// This triggers if verification passes
final PhoneVerificationCompleted verificationCompleted = (AuthCredential credential) async {
Navigator.of(context).pop();

AuthResult result = await _auth.signInWithCredential(credential);

FirebaseUser user = result.user;

if(user != null){
Navigator.push(context, MaterialPageRoute(
builder: (context) => HomeScreen(user: user,)
));
}else{
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Alert Dialog"),
content: Text('Error'),
);
}
);
}
};

// This triggers if verification fails
PhoneVerificationFailed verificationFailed = (AuthException exception) {
toast(exception.message, 'long');
};

// This is to send code to the user But i dont know how to resend
final PhoneCodeSent codeSent = (String verificationId, [int forceResendingToken]) {
var route = MaterialPageRoute(
builder: (BuildContext context) => LoginPhoneVerify(verificationId, phone)
);

Navigator.of(context).push(route);
};

// The main function
await _auth.verifyPhoneNumber(
phoneNumber: phone,
timeout: Duration(seconds: 0),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: null
);


}

我在以下线程中找到了适用于android的内容:

https://stackoverflow.com/a/44688838/10114772
private void resendVerificationCode(String phoneNumber, PhoneAuthProvider.ForceResendingToken token) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks, // OnVerificationStateChangedCallbacks
token); // ForceResendingToken from callbacks
}

但是那不是为了 flutter 朔迷离,请有人看看!

最佳答案

因此,在按照我的说明浏览完文档后,

verifyPhoneNumber()

方法将重新发送OTP代码。

关于flutter - 在Flutter中重新发送OTP代码Firebase电话身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61132218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com