gpt4 book ai didi

firebase - 如果密码或用户电子邮件格式不正确,则返回错误消息

转载 作者:行者123 更新时间:2023-12-03 03:32:53 25 4
gpt4 key购买 nike

嗨,伙计们,我已经将flutter连接到我的firebase项目并在Firebase中使用了AUTH功能,但是当密码错误或电子邮件用户错误时,我会显示一条错误消息。
这是我的代码:

Widget submitButton (){
return Container(
child: SizedBox(
width: 220,
height: 40,
child: MaterialButton(
elevation: 5,
onPressed: () async {
setState(() {
showProgress = true;
});

try {
final newUser = await _auth.signInWithEmailAndPassword(email: email, password: password);
print(newUser.toString());
if (newUser != null) {
Navigator.push(context, PageTransition(
type: PageTransitionType.fade,
child: WelcomeScreen(),
));
setState(() {
showProgress = false;
});

}
} catch (e) {}
},
child: Text('Accedi',style: TextStyle(color: Colors.black),),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(color: Colors.black12,width: 1)),
),

),
);
}

最佳答案

首先,您需要捕获错误,可以使用catchError()来做到这一点:

final newUser = await _auth.signInWithEmailAndPassword(email: email, password: password)
.catchError((err) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Error"),
content: Text(err.message),
actions: [
FlatButton(
child: Text("Ok"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
});
然后 showDialog将具有 err.message,其中将包含从Firebase身份验证收到的错误。

关于firebase - 如果密码或用户电子邮件格式不正确,则返回错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62910022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com