Home > Mobile >  how can i add a reset password function to my code to
how can i add a reset password function to my code to

Time:03-15

My flutter link on github: https://github.com/SpeedyTiger/flutter-app1

That's the link of my app over here, hope that anyone can help me to add a function to the reset password button that works on my firebase.

I have seen this link over here: https://www.back4app.com/docs/flutter/parse-sdk/users/flutter-reset-password

but i didn't understand it.

Thank you!

CodePudding user response:

Pretty simple, in your controller add this function

  Future<void> resetPassword({required String email}) async {
    try {
      return await auth.sendPasswordResetEmail(email: email);
    } catch (e) {
      print(e); // showError(title: '...', error: e);
    }
  }

and replace print(e) with Get.snackbar(...).

Since you're reusing the Get.snackbar(...) multiple times, I recommend that you refactor it out to it's own function with 2 parameters one for the title and the other for the error shown in the comment to keep your code clean.

To use in the widget:

          Button(
            isEnabled: controller.isValidEmail.value,
            height: 55.0,
            text: 'Reset Password',
            child: auth.isReseting.value ? const PAIndicator() : null,
            onTap: () async => await Services.auth.resetPassword(email: email),
          ),
  • Related