[英]Flutter: How to make user login automatically after register successfully?
I've bought a Flutter source code and finding ways to build a function to make user login automatically after register successfully in my app.我已经购买了 Flutter 源代码,并想方设法构建 function 以使用户在我的应用程序中注册成功后自动登录。
My app uses Firebase and email is authentication for register.我的应用程序使用 Firebase 和 email 是注册身份验证。
Users just need to put any emails with valid format like abc@xyz.com (not same old emails in database) and a password, press Sign up button then they will be automatically logged in and redirected to homepage .用户只需输入任何格式有效的电子邮件,如 abc@xyz.com(与数据库中的旧电子邮件不同)和密码,按注册按钮,他们将自动登录并重定向到主页。
This is a sample lines in register_view.dart file.这是 register_view.dart 文件中的示例行。
I try to write this code nearly last lines: Navigator.pushNamed(context, RoutePaths.home,);我尝试在最后几行编写此代码: Navigator.pushNamed(context, RoutePaths.home,); but after pressing Sign up button users are redirected to splash screens and not logged in.
但是在按下注册按钮后,用户被重定向到启动屏幕并且没有登录。
Can someone help me with this problem?有人可以帮我解决这个问题吗? Thank you very much!
非常感谢!
class __SignInButtonWidgetState extends State<_SignInButtonWidget> {
@override
Widget build(BuildContext context) {
return Container(
height: 50,
margin: const EdgeInsets.only(
left: PsDimens.space32, right: PsDimens.space32),
child: PSButtonWidget(
colorData: PsColors.buttonColor,
hasShadow: false,
width: double.infinity,
titleText: Utils.getString(context, 'register__register'),
onPressed: () async {
if (widget.nameTextEditingController!.text.isEmpty) {
callWarningDialog(context,
Utils.getString(context, 'warning_dialog__input_name'));
} else if (widget.emailTextEditingController!.text.isEmpty) {
callWarningDialog(context,
Utils.getString(context, 'warning_dialog__input_email'));
} else if (widget.passwordTextEditingController!.text.isEmpty) {
callWarningDialog(context,
Utils.getString(context, 'warning_dialog__input_password'));
} else {
if(Utils.checkEmailFormat(widget.emailTextEditingController!.text.trim())!){
await widget.provider.signUpWithEmailId(
context,
widget.onRegisterSelected,
widget.nameTextEditingController!.text,
widget.emailTextEditingController!.text.trim(),
widget.passwordTextEditingController!.text);
}else{
callWarningDialog(context,
Utils.getString(context, 'warning_dialog__email_format'));
}
}
},
),
);
}
}
Thank you very much!非常感谢!
When you got your result from当你得到你的结果时
String data = await widget.provider.signUpWithEmailId(
context,
widget.onRegisterSelected,
widget.nameTextEditingController!.text,
widget.emailTextEditingController!.text.trim(),
widget.passwordTextEditingController!.text);
Store data in variable after send it to success page.将数据发送到成功页面后将数据存储在变量中。
await widget.provider.signUpWithEmailId(
context,
widget.onRegisterSelected,
widget.nameTextEditingController!.text,
widget.emailTextEditingController!.text.trim(),
widget.passwordTextEditingController!.text).then((value) => Navigator.pushNamed(context, RoutePaths.home,));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.