flutter dio 重置密码 API 集成不起作用

发布于 2025-01-10 18:38:14 字数 863 浏览 0 评论 0原文

下面是我在单击“重置密码”按钮时实现的发送电子邮件的代码。但它不能正常工作。当我输入已注册的电子邮件时,它显示“未找到用户”。它应该显示“请检查您的电子邮件以重置密码”。如何解决这个问题

邮递员请求

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);
    }
  }

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);
    }
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2025-01-17 18:38:14

为什么要写response.data[“message”]。它应该是 response.data["data"],因为您收到的响应参数称为 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);
  }

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);
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文