Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
flatterrestapi试图获取属性';密码';非obj_Api_Flutter_Rest - Fatal编程技术网

flatterrestapi试图获取属性';密码';非obj

flatterrestapi试图获取属性';密码';非obj,api,flutter,rest,Api,Flutter,Rest,我正在尝试在flutter中使用restapi创建一个登录表单,但是我不断收到错误。 对于登录,API需要3个变量;电子邮件、密码和设备 这是我的登录功能 String email; String password; String device="mobile"; TextEditingController passwordcontroller=TextEditingController(); TextEditingController emai

我正在尝试在flutter中使用restapi创建一个登录表单,但是我不断收到错误。 对于登录,API需要3个变量;电子邮件、密码和设备

这是我的登录功能

String email;
  String password;
  
  String device="mobile";
  

  TextEditingController passwordcontroller=TextEditingController();
  TextEditingController emailcontroller=TextEditingController();

loginfunction(String email, String password, String device)async{

    // Map data={"email":email,
    // "password":password,"device":device};

    var jsonData;
    SharedPreferences sharedPreferences=await SharedPreferences.getInstance();
    var response= await http.post('https://f.nz/api/auth/Login',headers:{
      "key": "Client-Version",
      "value": "{{client_version}}-1",
      "type": "text"
    },

    body: {
      "email": email,
      "password": password,
      "device": device,
    });
   // return response.data;

    if (response.statusCode==200){
      jsonData= json.decode(response.body);
      setState(() {
        sharedPreferences.setString("token", jsonData["token"]);
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) =>
                    OtpPage()));
      });
    }
    else{
      print(response.body);
      print(response.statusCode);

      print(email);
      print(device);
    }

  }
这里是我在填写电子邮件和密码字段后调用函数的地方

GestureDetector(
              onTap: () async {
                try{
                  

                  await loginfunction(email, password,device);


                }
                catch(e){
                  setState(() {
                    error=e.message;
                  });

                }

              },
              child: Container(
                padding: EdgeInsets.fromLTRB(.0, 0.0, 0.0, 0.0),
                height: 35.0,
                width: 150.0,
                child: Material(
                  borderRadius: BorderRadius.circular(40.0),
                  color: Color(0xffa6ce38),
                  elevation: 7.0,
                  child: Center(
                    child: Text(
                      "Sign in",
                      style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 16.0, color: Colors.white),
                    ),
                  ),
                ),
              ),
            ),
每次我运行代码并尝试登录时,这就是终端中的错误

D/libc netbsd(7365):[getaddrinfo]:mtk hostname=fhm.soop.co.nz;servname=(null);netid=0;马克=0 D/libc netbsd(7365):getaddrinfo(app_uid:10366 D/libc netbsd(7365):getaddrinfo()uid属性: D/libc netbsd(7365):getaddrinfo()getuid():10366 D/libc netbsd(7365):[getaddrinfo]:mtk ai_addrlen=0;ai_canonname=(null);ai_flags=1024;ai_family=0 D/libc netbsd(7365):getaddrinfo:fhm.soop.co.nz从代理获取结果gai_error=0 I/颤振(7365): I/颤振(7365): I/颤振(7365): I/flatter(7365):遇到一个PHP错误 I/颤振(7365): I/颤振(7365):严重程度:通知

I/flatter(7365):消息:试图获取非对象的属性“email”

I/flatter(7365):文件名:auth/Login.php

I/颤振(7365):行号:43

I/颤振(7365): I/颤振(7365): I/颤振(7365):回溯:

I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365): I/flatter(7365):文件:C:\xampp\htdocs\api\application\controllers\auth\Login.php
I/颤振(7365):直线:43
I/颤振(7365):功能:\错误\处理程序

I/颤振(7365): I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365): I/flatter(7365):文件:C:\xampp\htdocs\api\application\libraries\REST\u Controller.php
I/颤振(7365):线路:708
I/颤振(7365):功能:索引柱

I/颤振(7365): I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365):
I/颤振(7365): I/flatter(7365):文件:C:\xampp\htdocs\api\index.php
I/颤振(7365):线条:308
I/颤振(7365):功能:需要一次

I/颤振(7365): I/颤振(7365):
I/颤振(7365):
I/颤振(7365): I/颤振(7365): I/颤振(7365): I/颤振(7365): I/flatter(7365):遇到一个PHP错误 I/颤振(7365): I/颤振(7365):严重程度:通知

I/flatter(7365):消息:尝试获取非obj的属性“密码” I/颤振(7365):400 I/颤振(7365):email@email.com
I/颤振(7365):mobile

如果您使用的是数据库中不存在的电子邮件,这是来自php服务器的结果。我看到您的错误是
email@email.com
。您的服务器正在查找用户,但未找到该用户,并返回null。或者您可能在服务器端错误地解析了数据。我将首先在那里进行检查

你的错误还说

Message: Trying to get property 'email' of non-object

I/flutter ( 7365):
Filename: auth/Login.php
message:  A PHP Error was encountered
所以,很明显,这不是一个颤振问题,只要确保您确实在将您的姓名和密码从TextEditingController传递到您的POST请求

为了验证这一理论,在请求中硬编码您的凭证,看看错误是否仍然存在并且没有改变,然后一定要转到您的php代码

body: {
      "email": 'email@gmail.com',
      "password": 'youSuperStrongpassword124234',
      "device": device,
    });

你也应该<代码> JSONEnCOD/<代码>你的POST请求的正文。

我已经尝试过对这些值进行硬编码,但是我仍然会得到错误。但是当我试着在邮递员上运行相同的东西时,它会对你的BoyType进行编码。非常感谢。