getListModelRest method
dynamic
getListModelRest({})
Implementation
getListModelRest({
required String serviceOrEntityName,
required String methodName,
required Types type,
String? body,
required Function(Map<String, dynamic> json) fromMap,
CubaEntityFilter? filter,
}) async {
Uri url = Uri.parse(Kinfolk.createRestUrl(serviceOrEntityName, methodName, type));
oauth2.Client? client = await Authorization().client;
var response;
if (filter != null) {
assert(type == Types.entities, "Filter can be used only with Types.entities");
response = await getPostResponse(
url: url,
body: filter.toJson(),
client: client!,
);
} else {
if (body != null) {
response = await getPostResponse(url: url, body: body, client: client!);
} else {
response = await getGetResponse(url: url, client: client!);
}
}
var respBody = response.body;
if (respBody.runtimeType == String && respBody.isEmpty) return null;
var source = jsonDecode(respBody);
assert(source is List, "Response is" + "\n$respBody");
return source.map((item) => fromMap(item)).toList();
}