【发布时间】:2021-04-24 00:58:51
【问题描述】:
我正在努力解决这个问题。问题是无论我做什么,我都无法为我的应用程序捕获异常。程序而不是打印错误只是卡住了(由于未捕获的异常)。
这是我的简单代码。有人可以帮我解决这个问题吗?
Future<void> onRegisterPress(
BuildContext context,
TextEditingController fName,
TextEditingController lName,
TextEditingController email,
TextEditingController password) async {
if (isValid(fName.text, lName.text, email.text, password.text)) {
//TODO: Exception not caught
try {
var userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email.text, password: password.text);
} on PlatformException catch (e) {
print('Failed with error code: ${e.code}');
print(e.message);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(headline: 'Exception Caught!')));
}
Navigator.push(
context, MaterialPageRoute(builder: (context) => MyLoginPage()));
}
}
更新 1:
User user = FirebaseAuth.instance.currentUser;
try {
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email.text, password: password.text);
} on FirebaseAuthException catch (e) {
print('Failed with error code: ${e.code}');
print(e.message);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(headline: 'Exception Caught!')));
}
使用 FirebaseAuthException 更新代码,很遗憾没有效果。
错误是: Error Screenshot
【问题讨论】:
标签: firebase flutter firebase-authentication