getServerCount method
override
Gets the latest value from the server.
Implementation
@override
Future<int?> getServerCount() async {
final User user = ProductQuery.getWriteUser();
final ProductSearchQueryConfiguration configuration = type.getConfiguration(
user.userId,
1,
1,
ProductQuery.getLanguage(),
// one field is enough as we want only the count
// and we need at least one field (no field meaning all fields)
<ProductField>[ProductField.BARCODE],
);
try {
final SearchResult result = await SearchProductsManager.searchProducts(
user,
configuration,
uriHelper: ProductQuery.getUriProductHelper(
productType: ProductType.food,
),
type: SearchProductsType.count,
);
return result.count;
} catch (e) {
Logs.e(
'Could not count the number of products for $type, ${user.userId}',
ex: e,
);
return null;
}
}