I was able to solve using the latest version, with Credentials.
If anyone wants to use it that way, here’s the code:
Future<void> verificaPhone() async {
try {
final phoneNumber = "+55" +
_phoneNumberController.text.replaceAll("(", "")
.replaceAll(")", "")
.replaceAll("-", "");
if(_phoneNumberController.text.length > 13) {
final PhoneVerificationCompleted verificationCompleted =
(AuthCredential phoneAuthCredential) {
_auth.signInWithCredential(phoneAuthCredential);
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => ConfereCadastro()));
print('Auto login realizado: user');
// setState(() {
// Navigator.of(context).pushReplacement(
// MaterialPageRoute(builder: (context) => ConfereCadastro()));
// print('Auto login realizado: user');
// });
};
final PhoneVerificationFailed verificationFailed = (
AuthException authException) {
print('Verificação para o número ${phoneNumber
.toString()} falhou. Código: ${authException
.code}. Motivo: ${authException.message}');
// setState(() {
// print('Verificação para o número ${phoneNumber
// .toString()} falhou. Código: ${authException
// .code}. Motivo: ${authException.message}');
// });
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
this.verificationId = verificationId;
print("Código enviado para " + phoneNumber);
setState(() => codigoEnviado = true);
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
this.verificationId = verificationId;
setState(() => codigoEnviado = false);
print("Tempo limite esgotado!");
};
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: const Duration(seconds: 30),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
}
} catch (e) {
print("_signInWithPhoneNumber ERROR: ${e.toString()}");
}
}
Future<void> _signInWithPhoneNumber(String smsCode) async {
if(hasConnection == true) {
try {
AuthCredential credential = PhoneAuthProvider.getCredential(verificationId: verificationId, smsCode: smsCode);
final FirebaseUser user = await _auth.signInWithCredential(credential);
print('Usuário logado com sucesso $user');
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => ConfereCadastro()));
} catch (e) {
print("verificaPhone ERROR: ${e.toString()}");
}
} else {
checkInternet();
}
}
How strange if you have already checked all the data. Did you also confirm the firebase startup settings? Other firebase things work normally?
– George
Yes I already got it working, there was a configuration missing, the debug SHA1, what I had configured in Firebase was the launch SHA1.
– Matheus