I'm going through a weird behavior using the signInWithEmailAndPassword
method of firebase_auth
the try catch
block should catch if an error is thrown but a PLatformException
flows up in the editor like I did call a normal async/await method without catching errors :
the weird thing is that I already used the same code in a previous project and it's working fine, I did the same configuration, and it's working fine with correct auth data, just if there is an error it doesn't catch it my code :
Future handleLoginProcess(BuildContext context) async {
_handleInputsCases();
_startLoading();
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: "[email protected]", password: "SuperSecretPassword!");
} on FirebaseAuthException catch (e) {
print('Failed with error code: ${e.code}');
print(e.message);
}
_endLoading();
}
the thrown error seem to direct me to this:
if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining) {
throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace);
} else {
throw const FormatException('Invalid envelope');
}
I'm missing something, what are the possible reasons to this, is it something related to vscode?
please share your ideas with me, thanks
CodePudding user response:
If this code working well in your another project. then you should check SDK Version of both projects. You can find SDK version in YAML file.
CodePudding user response:
Check your flutter implementation too.
In pubspec.yaml
firebase_auth: ^3.11.2
Code
Future loginWithUserEmail({@required String email, @required String password}) async{
try{
var userCredential = await _firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password
);
//await _populateCurrentUser(userCredential.user);
return userCredential.user != null;
}catch(error){
return error.toString();
}
}