skip to Main Content

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.

My app uses Firebase and email is authentication for register.

Users just need to put any emails with valid format like [email protected] (not same old emails in database) and a password, press Sign up button then they will be automatically logged in and redirected to homepage.

This is a sample lines in register_view.dart file.

I try to write this code nearly last lines: 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!

2

Answers


  1. 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.

    Login or Signup to reply.
  2. await widget.provider.signUpWithEmailId(
        context,
        widget.onRegisterSelected,
        widget.nameTextEditingController!.text,
        widget.emailTextEditingController!.text.trim(),
        widget.passwordTextEditingController!.text).then((value) => Navigator.pushNamed(context, RoutePaths.home,));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search