I want to verify a phone number of a user and then only allow that user to signup. But for this when I call verifyPhoneNumber even if I apply await it does not wait till the verification is completed. it executes the next line. So what I want to do is unless the either of verificationCompleted, verificationFailed, codeAutoRetrievalTimeout completes I want to wait and then only executes the code which creates the document for the user in database.
Any help will be appreciated!!!
static Future signUp(BuildContext context, String name, String phoneNumber,
String email, String gender) async {
await auth.verifyPhoneNumber(
phoneNumber: phoneNumber,
verificationCompleted: (credential) async {
await auth.signInWithCredential(credential);
},
verificationFailed: _verificationFailed,
codeSent: (String verificationId, int resendToken) async{
await _codeSent(verificationId, resendToken, context);
},
codeAutoRetrievalTimeout: (String timeout) {});
if (auth.currentUser != null) {
await DB.users.doc(auth.currentUser.uid).set({
name: name,
phoneNumber: phoneNumber,
email: email,
});
}
return;
}
Thanks!!