0

I am facing a "The SMS code has expired. Please resend the verification code to try again" while I am trying to sign up with a phone from a real android phone, not a simulator although I did not have the same issue while sighing up from a simulator and a solution said the new device enters the SMS code automatically but I don't understand how to apply it with flutter

Future<void> signUpWithPhone({
required PhoneAuthCredential phonecredintial,
required String? phoneNumber,
BuildContext? context,
File? image,
}) async {
  try {
    final authcredintial = await _auth.signInWithCredential(phonecredintial);
  // add the user details to the database
    _userId = authcredintial.user!.uid;

  final ref = FirebaseStorage.instance
      .ref()
      .child('Profile_Image')
      .child(_userId! + '.jpg');
  await ref.putFile(image!).whenComplete(
    () async {
      final profileImageUrl = await ref.getDownloadURL();

      await FirebaseFirestore.instance
          .collection(conUserCollectios)
          .doc(phoneNumber)
          .set(
        {
          conuserName: username,
          conuserCountry: usercountry,
          conuserDialCode: userdialCode,
          conuserPhone: userphone,
          conUserId: authcredintial.user!.uid,
          conUserImageUrl: profileImageUrl.toString(),
        },
      ).whenComplete(
        () {
          _userId = authcredintial.user!.uid;
          Navigator.of(context!).pushNamed(AddFriendScreen.routeName);
        },
      );
    },
  );

  // if (_userId != null) {
  //   Navigator.of(context).pushNamed(MultiUserChats.routeNames);
  // }
} catch (e) {
  print(e);
}
 }
 Future<void> enterPhoneNumber({
required String phoneNumber,
BuildContext? context,
String? name,
String? country,
String? dialCode,
 }) async {
try {
  await _auth.verifyPhoneNumber(
    phoneNumber: phoneNumber,
    verificationCompleted: (phoneauth) async {
      await signUpWithPhone(
        phonecredintial: phoneauth,
        context: context,
        phoneNumber: phoneNumber,
      );
    },
    verificationFailed: (FirebaseAuthException e) {
      if (e.code == 'invalid-phone-number') {
        print('The provided phone number is not valid.');
      }

      print(e.message);
      print('The provided phone number is not valid.');
    },
    codeSent: (verificationId, resendingToken) async {
      _verifactionID2 = verificationId;

      Navigator.of(context!).pushNamed(OtpScreen.routeNames,
          arguments: [verificationID, phoneNumber]);
      username = name;
      usercountry = country;
      userdialCode = dialCode;
      userphone = phoneNumber;
    },
    codeAutoRetrievalTimeout: (verificationId) async {},
    //timeout: Duration(seconds: 60),
  );
} catch (e) {}
}

0 Answers0