getListByFilterEx method
Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
This method shall be called by a public getListByFilter method from child class that receives FilterParams and converts them into a filter function.
correlationId
(optional) transaction id to trace execution through call chain.filter
(optional) a filter function to filter itemspaging
(optional) paging parameterssort
(optional) sorting parametersselect
(optional) projection parameters (not used yet) Return Future that receives a data list Throw error.
Implementation
Future<List<T>> getListByFilterEx(
String? correlationId, Function? filter, Function? sort, select) async {
var items = this.items;
// Apply filter
if (filter != null) {
items = List<T>.from(items.where((item) => filter(item)));
}
// Apply sorting
if (sort != null) {
items.sort((a, b) {
var sa = sort(a);
var sb = sort(b);
if (sa > sb) return -1;
if (sa < sb) return 1;
return 0;
});
}
logger.trace(correlationId, 'Retrieved %d items', [items.length]);
return items;
}