addTask method
- BuildContext context, {
- required bool displaySnackbar,
Adds the related background task.
Implementation
Future<void> addTask(
BuildContext context, {
required bool displaySnackbar,
}) async {
final List<String> barcodes = <String>[];
final List<String> categories = <String>[];
final List<List<String>> origins = <List<String>>[];
final List<List<String>> labels = <List<String>>[];
final List<String> pricePers = <String>[];
final List<bool> pricesAreDiscounted = <bool>[];
final List<double> prices = <double>[];
final List<double?> pricesWithoutDiscount = <double?>[];
final List<String> discountTypes = <String>[];
for (final PriceAmountModel priceAmountModel in _priceAmountModels) {
barcodes.add(priceAmountModel.product.barcode);
categories.add(priceAmountModel.product.categoryTag);
origins.add(priceAmountModel.product.originTags);
// TODO(monsieurtanuki): to be implemented when supported by "prices"
labels.add(<String>[]);
pricePers.add(priceAmountModel.product.pricePer.offTag);
pricesAreDiscounted.add(priceAmountModel.promo);
prices.add(priceAmountModel.checkedPaidPrice);
pricesWithoutDiscount.add(priceAmountModel.checkedPriceWithoutDiscount);
discountTypes.add(priceAmountModel.discountType?.offTag ?? '');
}
if (proof != null) {
return BackgroundTaskAddOtherPrice.addTask(
context: context,
// per receipt
locationOSMId: proof!.locationOSMId!,
locationOSMType: proof!.locationOSMType!,
date: proof!.date!,
currency: proof!.currency!,
proofId: proof!.id,
// per item
barcodes: barcodes,
categories: categories,
origins: origins,
labels: labels,
pricePers: pricePers,
pricesAreDiscounted: pricesAreDiscounted,
prices: prices,
pricesWithoutDiscount: pricesWithoutDiscount,
discountTypes: discountTypes,
);
}
return BackgroundTaskAddPrice.addTask(
context: context,
// proof display
cropObject: cropParameters!,
// per receipt
locationOSMId: location!.osmId,
locationOSMType: location!.osmType,
date: date,
proofType: proofType,
currency: currency,
// per item
barcodes: barcodes,
categories: categories,
origins: origins,
labels: labels,
pricePers: pricePers,
pricesAreDiscounted: pricesAreDiscounted,
prices: prices,
pricesWithoutDiscount: pricesWithoutDiscount,
displaySnackbar: displaySnackbar,
readyForPriceTagValidation: readyForPriceTagValidation,
discountTypes: discountTypes,
);
}