简体   繁体   English

Flutter:注册成功后如何让用户自动登录?

[英]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.

相关问题 Flutter Firebase - 注册后无法导航到登录屏幕 - Flutter Firebase - Unable to Navigate to Login Screen after Register Firebase 登录/注册后无限加载 - Firebase Infinite Loading after Login/Register 如何在验证其 email 后重定向 flutter 中的用户? - How to redirect a user in flutter after verified their email? Firebase 用户的显示名称在注册后没有更新。 我需要重新启动应用程序才能使其正常工作 - Firebase user's displayName does not update after register. I need to restart the app to make it work 在 flutter 中通过身份验证后将用户从登录/注册页面导航到主页的正确方法 - Proper way of navigating user from login/signup page to home page after authentication in flutter 无法从 Flutter 注册 FireBase 用户 - Cant register FireBase user from Flutter 如何使用 Flutter 和 Firbase 进行基于角色的登录 - How to make Role-Based login with Flutter and Firbase 如何在flutter中使用firebase手机号和密码进行登录注册 - How to make login signup with firebase phone number and password in flutter 如何在Flutter中谷歌登录后重定向到另一个页面 - How to redirect to another page after google login in Flutter Firebase Android - 如何以不同用户身份登录(使用 Google 登录后) - Firebase Android - how to login as different user (after signing in with Google)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM