how can i add a reset password function to my code to

Issue

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!

Solution

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),
          ),

Answered By – Mohamed Mohamed

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *