【发布时间】:2021-06-12 10:34:09
【问题描述】:
我有一个两步登录表单,用户首先输入他们的电子邮件,然后被带到他们输入密码的下一页。在将用户带到密码页面之前,我想检查用户输入的电子邮件是否有效以及它是否存在于 firebase 中。我已经阅读了一些关于使用fetchSignInMethodsForEmail 的帖子。但是,我不太确定如何实现。
这个想法是,如果电子邮件确实存在,则将用户带到密码页面,但是,如果电子邮件不存在,则会弹出一个带有按钮的快餐栏,将用户带到注册页面。我该怎么做呢?
这就是我目前所拥有的......
FirebaseAuth auth = FirebaseAuth.instance;
final nextButton = Container(
margin: const EdgeInsets.only(
top: 30.0,
),
child: FloatingActionButton(
onPressed: () async {
try {
List<String> userSignInMethods = await auth.fetchSignInMethodsForEmail(email)(
email: _emailController.text,
);
if (userSignInMethods != null) {
final page = LoginPassword();
Navigator.of(context).push(CustomPageRoute(page));
}
} catch (e) {
print(e);
//TODO: Snackbar
}
},
tooltip: 'Next',
backgroundColor: AppTheme.define().primaryColor,
child: Icon(
AppIcons.next_button,
size: 20.0,
),
),
);
fetchSignInMethodsForEmail 未正确实现,我收到错误消息。
【问题讨论】:
-
捕获异常后处理错误,因为如果电子邮件已经存在,则会抛出该异常。
-
你得到什么错误?