putObjData<T> method

Future<RocketModel> putObjData<T>(
  1. int id,
  2. String endpoint,
  3. RocketModel<T> model, {
  4. bool multi = false,
  5. dynamic inspect(
    1. dynamic data
    )?,
})

دالة خاصة بتعديل البيانات على شكل بالنموذج الذي تم تمريره مع الدالة

model=>(النموذج)

inspect => (،ارجاع القيمة المراد استخدامها ,json التنقيب داخل )

Implementation

Future<RocketModel> putObjData<T>(
    int id, String endpoint, RocketModel<T> model,
    {bool multi = false, Function(dynamic data)? inspect}) async {
  model.load(true);
  Uri url = Uri.parse(this.url + "/" + endpoint + "/" + id.toString() + "/");
  http.Response? response;
  try {
    response = await http
        .put(url, body: json.encode(model.toJson()), headers: headers)
        .whenComplete(() => model.load(false));
    model.setFailed(false);
    return _objData<T>(response, model,
        inspect: inspect, multi: multi, endpoint: endpoint);
  } catch (e, s) {
    String body = "";
    int statusCode = 0;
    if (response != null) {
      body = response.body;
      statusCode = response.statusCode;
    }
    model.setException(RocketException(
        response: body,
        statusCode: statusCode,
        exception: e.toString(),
        stackTrace: s));
    model.setFailed(true);
    return Future.value(model);
  }
}