Search code examples
flutterapidio

flutter dio reset password API integrating not working


below is the code I implement to send email when click Reset password button. but its not working properly. when I enter already registered email it says "No User Found". it should display"Please check your email to reset password". how to solve this issue

postman request

class _LoginFormState extends State<SignUpForm> {
  final _formKey = GlobalKey<FormState>();
  //String _userName = "";
  String email = "";

  Future Resetpassword() async{
    try {
      var response = await Dio().post('https://app2-hi.herokuapp.com//user/forgotpassword',data:

    {
    "email": email,
    }
    );

    if(response.data["message"] == " Please check your email to reset password."){
    Get.snackbar("success","Email Sent Sucessfully!");
  

    }else{
    Get.snackbar("error", "No User Found");
    }
    print("res: $response");
    } catch (e) {

    Get.snackbar("error", "No User Found");
    print(e);
    }
  }

Solution

  • Why did you write response.data["message"]. It should be response.data["data"] as the response parameter you receive is called data.

      if (response.data["data"] == "Please check your email to reset password.") {
        Get.snackbar("success","Email Sent Sucessfully!");
      } else {
        Get.snackbar("error", "Email Not Sent. Please try again.");
      }
        print("res: ${response.data}");
      } catch (e) {
        Get.snackbar("error", e.toString());
        print(e);
      }