flutter 过滤器||在put请求中得到500内部错误,但在postman上工作正常

6pp0gazn  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(70)

我正在处理一个复选框,当用户单击该复选框时,它将向服务器发送一个put请求,该复选框将永久更改为bluetick。
这是工作的 Postman ,而不是在我的Flutter应用程序。
这是我的put服务,我已经删除了与XXXX的API链接:-

Future <OrdersPutModel> ordersPutRequest(ApiOrdersData data)  async{
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String? jwt = prefs.getString('jwt');

  http.Response response;
  response = await http.put(Uri.parse("http://xxxx/api/orders/19"),headers: 
  <String,String>{
  'Authorization' : 'Bearer $jwt',
   'Content-Type' : 'multipart/form-data; boundary=---011000010111000001101001'
  },
    body: jsonEncode(<String,String>{
         'manualBillCompletion': data.manualBillCompletion!,
         'balancePayment': data.balancePayment!
     })
    );

  if(response.statusCode == 200) {
   print("response.statusCode ${'successful'}");
   return OrdersPutModel.fromJson(jsonDecode(response.body));
  }
 else {
   print("error ${response.statusCode}");
   throw Exception('Failed to load data');
  }
}

我的看跌期权类别:-

class ApiOrdersData{
 String? manualBillCompletion;
 String? balancePayment;

 ApiOrdersData({
 required this.manualBillCompletion,
 required this.balancePayment
 });
 }

我的订单UI代码:-

snapshot.data?.data.attributes
                                          .totalBills[index].manualBillCompletion == false
                                          ? Row(
                                        children: [
                                          Text(
                                            "Not Completed",
                                            style: TextStyle(
                                                color: Color.fromRGBO(
                                                    17, 112, 222, 1),
                                                fontSize: 12,
                                                fontWeight: FontWeight.w600),
                                          ),
                                          Checkbox(
                                              focusColor: Color(0xff1170DE),
                                              activeColor: Color(0xff1170DE),
                                              shape: CircleBorder(),
                                              value: snapshot.data?.data.attributes
                                                  .totalBills[index].manualBillCompletion,
                                              onChanged: (newValue) {
                                                setState(() {
                                                  snapshot.data?.data.attributes
                                                      .totalBills[index].manualBillCompletion = newValue!;
                                                });
                                                sendCheckBoxRequest();
                                              }),
                                        ],
                                      )
                                          :
                                      Row(
                                        children: [
                                          Text(
                                            "Completed",
                                            style: TextStyle(
                                                color: Color.fromRGBO(
                                                    17, 112, 222, 1),
                                                fontSize: 12,
                                                fontWeight: FontWeight.w600),
                                          ),
                                          Checkbox(
                                              focusColor: Color(0xff1170DE),
                                              activeColor: Color(0xff1170DE),
                                              shape: CircleBorder(),
                                              value: snapshot.data?.data.attributes
                                                  .totalBills[index].manualBillCompletion,
                                              onChanged: (newValue) {

                                                setState(() {
                                                  // snapshot.data?.data.attributes
                                                  //     .totalBills[index].manualBillCompletion = newValue!;
                                                });
                                                // _futureOrdersModel = ordersPutRequest(ApiOrdersData(manualBillCompletion:'true', balancePayment:'0'));
                                              }),
                                        ],
                                      ),

ujv3wf0j

ujv3wf0j1#

在正文中,只需传递Map变量...不要使用json.encode。并尝试在控制台中打印状态代码。

相关问题