getObjData<T> method
دالة خاصة لجلب البيانات على شكل النموذج الذي تم تمريره مع الدالة
model
=>(النموذج)
عندما يكون (متعدد) صحيح هذا يعني أنك ستجد بيناتك في (مصفوفة) داخل (النموذج) الخاص بك على شكل نفس النموذج يمكنك الوصول لهذه البيانات عن طريق المتغير
multi
=>(متعدد)
List=>(مصفوفة)
inspect
=> List
Implementation
Future getObjData<T>(String endpoint, McModel<T> model,
{Map<String, dynamic>? params,
bool multi = false,
Function(dynamic data)? inspect}) async {
model.load(true);
String srch = params != null ? _mapToString(params) : "";
Uri url = Uri.parse(this.url + "/" + endpoint + '?' + srch);
http.Response? response;
try {
response = await http
.get(url, headers: headers)
.whenComplete(() => model.load(false));
model.setFailed(false);
return _objData<T>(response, model,
multi: multi, inspect: inspect, endpoint: endpoint);
} catch (e, s) {
String body = "";
int statusCode = 0;
if (response != null) {
body = response.body;
statusCode = response.statusCode;
}
model.setException(McException(
response: body,
statusCode: statusCode,
exception: e.toString(),
stackTrace: s));
model.setFailed(true);
}
}