getCache static method
- BuildContext context,
- ProductType? productType
Returns an app-local/downloaded cache, or null if it failed.
Implementation
static Future<OrderedNutrientsCache?> getCache(
BuildContext context,
ProductType? productType,
) async {
final OrderedNutrientsCache cache = OrderedNutrientsCache._(productType);
final LocalDatabase localDatabase = context.read<LocalDatabase>();
// quickest
cache._orderedNutrients = await cache._getStaticVersion();
if (cache._orderedNutrients != null) {
return cache;
}
// less quick, but still local
cache._orderedNutrients = await cache._getDatabaseVersion(localDatabase);
if (cache._orderedNutrients != null) {
return cache;
}
// server version, the very first time
if (!context.mounted) {
return null;
}
cache._orderedNutrients = await LoadingDialog.run<OrderedNutrients>(
context: context,
future: cache._download(localDatabase),
);
if (cache._orderedNutrients != null) {
return cache;
}
if (context.mounted) {
await LoadingDialog.error(context: context);
}
return null;
}