fetchAndRefresh method
- required String barcode,
- required BuildContext context,
Fetches the product from the server and refreshes the local database.
With a waiting dialog. Returns true if successful.
Implementation
Future<bool> fetchAndRefresh({
required String barcode,
required BuildContext context,
}) async {
final LocalDatabase localDatabase = context.read<LocalDatabase>();
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final FetchedProduct? fetchAndRefreshed =
await LoadingDialog.run<FetchedProduct>(
future: silentFetchAndRefresh(
localDatabase: localDatabase,
barcode: barcode,
),
context: context,
title: appLocalizations.refreshing_product,
);
if (fetchAndRefreshed == null) {
// the user probably cancelled
return false;
}
if (fetchAndRefreshed.product == null) {
if (context.mounted) {
await LoadingDialog.error(
context: context,
title: fetchAndRefreshed.getErrorTitle(appLocalizations),
);
}
return false;
}
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SmoothFloatingSnackbar.positive(
context: context,
text: appLocalizations.product_refreshed,
),
);
}
return true;
}