getList method
Future<ResultList<M> >
getList({
- int page = 1,
- int perPage = 30,
- bool skipTotal = false,
- String? expand,
- String? filter,
- String? sort,
- String? fields,
- Map<
String, dynamic> query = const {}, - Map<
String, String> headers = const {}, - RequestPolicy requestPolicy = RequestPolicy.cacheAndNetwork,
- Duration timeout = const Duration(seconds: 30),
override
Returns paginated items list.
Implementation
@override
Future<ResultList<M>> getList({
int page = 1,
int perPage = 30,
bool skipTotal = false,
String? expand,
String? filter,
String? sort,
String? fields,
Map<String, dynamic> query = const {},
Map<String, String> headers = const {},
RequestPolicy requestPolicy = RequestPolicy.cacheAndNetwork,
Duration timeout = const Duration(seconds: 30),
}) async {
return requestPolicy.fetch<ResultList<M>>(
label: service,
client: client,
remote: () => super
.getList(
page: page,
perPage: perPage,
skipTotal: skipTotal,
expand: expand,
filter: filter,
fields: fields,
sort: sort,
query: query,
headers: headers,
)
.timeout(timeout),
getLocal: () async {
final limit = perPage;
final offset = (page - 1) * perPage;
final items = await client.db
.$query(
service,
limit: limit,
offset: offset,
expand: expand,
fields: fields,
filter: filter,
sort: sort,
)
.get();
final results = items.map((e) => itemFactoryFunc(e)).toList();
final count = await client.db.$count(service);
final totalPages = (count / perPage).ceil();
return ResultList(
page: page,
perPage: perPage,
items: results,
totalItems: count,
totalPages: totalPages,
);
},
setLocal: (value) async {
// Use the more efficient merge operation for list fetches.
await client.db
.mergeLocal(service, value.items.map((e) => e.toJson()).toList());
},
);
}