Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
颤振如何处理http服务器端验证错误_Http_Dart_Flutter - Fatal编程技术网

颤振如何处理http服务器端验证错误

颤振如何处理http服务器端验证错误,http,dart,flutter,Http,Dart,Flutter,我试图在登录表单上显示服务器端错误。 我试图在数据可用时更改状态。 但它不起作用。有人能帮忙吗 或者有没有更好的方法 Future<dynamic> apiRequest(map) async { String url = 'https://localhost/api/login'; var response = await http.post(Uri.encodeFull(url), body: map, headers: {"Accept": "

我试图在登录表单上显示服务器端错误。 我试图在数据可用时更改状态。 但它不起作用。有人能帮忙吗

或者有没有更好的方法

 Future<dynamic> apiRequest(map) async {
    String url = 'https://localhost/api/login';
    var response = await http.post(Uri.encodeFull(url),
        body: map, headers: {"Accept": "application/json"});
    var res = json.decode(response.body);
    return res;
  }

 void _submit() async {
    if (this._formKey.currentState.validate()) {
      _formKey.currentState.save(); // Save our form now.

 var map = {
        'email_id': '',
        'password': '',
      };
      var hello = await apiRequest(map);

     setState(() {
       email_id_error = hello["errors"]["email_id"];
      });

    } else {
      setState(() {
        _autovalidate = true;
      });
    }
  }

 new Text(email_id_error),
你可以试试这个

void _submit() async {
    if (this._formKey.currentState.validate()) {
      _formKey.currentState.save(); // Save our form now.
     var map = {
        'email_id': '',
        'password': '',
      };
      var hello = await apiRequest(map);
      if(hello.statusCode ==4003){
        setState(() {
           email_id_error = hello.responseBody["errors"]["email_id"];
        });
      }    
    } else {
      setState(() {
        _autovalidate = true;
      });
    }
  }
void _submit() async {
    if (this._formKey.currentState.validate()) {
      _formKey.currentState.save(); // Save our form now.
     var map = {
        'email_id': '',
        'password': '',
      };
      var hello = await apiRequest(map);
      if(hello.statusCode ==4003){
        setState(() {
           email_id_error = hello.responseBody["errors"]["email_id"];
        });
      }    
    } else {
      setState(() {
        _autovalidate = true;
      });
    }
  }