getCustomer method
dynamic
getCustomer({})
Implementation
getCustomer(
{int? id,
String? context,
int? page,
int? perPage,
String? search,
List<int>? exclude,
List<int>? include,
int? offset,
String? order,
String? orderBy,
String? email,
String? role}) async {
var request_api = 'customers';
// If an ID is provided, append it to the request_api
if (id != null) {
request_api += '/$id';
}
// Constructing the query parameters based on the provided parameters
if (context != null ||
page != null ||
perPage != null ||
search != null ||
exclude != null ||
include != null ||
offset != null ||
order != null ||
orderBy != null ||
email != null ||
role != null) {
request_api += '?';
if (context != null) request_api += 'context=$context&';
if (page != null) request_api += 'page=$page&';
if (perPage != null) request_api += 'per_page=$perPage&';
if (search != null) request_api += 'search=$search&';
if (exclude != null) request_api += 'exclude=${exclude.join(",")}&';
if (include != null) request_api += 'include=${include.join(",")}&';
if (offset != null) request_api += 'offset=$offset&';
if (order != null) request_api += 'order=$order&';
if (orderBy != null) request_api += 'orderby=$orderBy&';
if (email != null) request_api += 'email=$email&';
if (role != null) request_api += 'role=$role&';
// Removing the last '&' character if present
request_api = request_api.endsWith('&')
? request_api.substring(0, request_api.length - 1)
: request_api;
}
Response res = await ApiServices()
.getRequest(request_api, baseUrl, consumerKey, consumerSecret);
var decoded_data = json.decode(res.body);
if (id != null) {
return CustomerModel.fromJson(decoded_data);
} else {
return (decoded_data as List)
.map((customerJson) => CustomerModel.fromJson(customerJson))
.toList();
}
}