Auto detect firebase Phone Auth sms code in Flutter

Please read properly and then comment, hope this help full for software community.

I unable to auto detect firebase phone auth sms, when i test in android it’s work without doing anything, but when i tried it in flutter sms not detected automatically, require manually type sms code, I did not find any documentation to do this process automatically.
I wan’t to know how to detect automatically that sms code from Firebase phone auth

Future<void> verifyPhone() async {

starTimer();
phoneNumber = contryCode+mobile_controller.text;

final PhoneCodeAutoRetrievalTimeout autoReRetrive = (String verId) {
  this.verificationId = verId;

};

final PhoneCodeSent smsCodesent = (String verId, [int forceCodeResent]) {
  this.verificationId = verId;


  pageController.animateToPage(2, duration: Duration(milliseconds: 300), curve: Curves.easeInBack);
  /*smsCodeDialog(context).then((value) {
    print("VERIFY PHONE SIGN IN");
  });
  */

};
final PhoneVerificationCompleted phoneVerificationCompleted =
    (PhoneAuthCredential creditional) {
  print("VERIFY PHONE AUTH SUCESS");
  this.mPhoneCreditional=creditional;
  //_controller.animateToPage(3, duration: Duration(milliseconds: 300), curve: Curves.easeIn);
  loginIn(creditional);
};
final PhoneVerificationFailed phoneVerificationFailed =
    (FirebaseAuthException excepton) {
  Fluttertoast.showToast(
      msg: excepton.message,
      toastLength: Toast.LENGTH_LONG,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.red,
      textColor: Colors.white,
      fontSize: 16.0
  );
  print("VERIFY PHONE AUTH FAILED " + excepton.message);
};
FirebaseAuth mAuth=await FirebaseAuth.instance;
mAuth.setLanguageCode("en");
await mAuth.verifyPhoneNumber(
    phoneNumber: phoneNumber,
    timeout: const Duration(seconds: 45),
    verificationCompleted: phoneVerificationCompleted,
    verificationFailed: phoneVerificationFailed,
    codeSent: smsCodesent,
    codeAutoRetrievalTimeout: autoReRetrive);


}

Source: Android Questions

LEAVE A COMMENT