You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App/lib/pages/pharmacies/compare-list.dart

46 lines
1.5 KiB
Dart

import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/material.dart';
class CompareList with ChangeNotifier {
List<PharmacyProduct> _product = [];
List<PharmacyProduct> get productListItems => _product;
void addItem(data, context) {
if (_product.length == 0) {
_product.add(data);
AppToast.showSuccessToast(message:TranslationBase.of(context).addToCompareMsg
// 'You have added a product to the Compare list'
);
} else {
for (int i = 0; i < _product.length; i++) {
if (_product.length < 3 && _product[i].id != data.id) {
_product.add(data);
AppToast.showSuccessToast(message:TranslationBase.of(context).addToCompareMsg
// 'You have added a product to the Compare list'
);
break;
} else if(_product[i].id == data.id){
AppToast.showErrorToast(message:TranslationBase.of(context).itInListMsg
// 'the item is already in the list'
);
} else if(_product.length == 3){
AppToast.showErrorToast(message: TranslationBase.of(context).compareListFull
// 'your compare list is full'
);
}
}
}
notifyListeners();
}
void deleteItem(data) {
for (int i = 0; i < _product.length; i++) {
if (_product[i].id == data) _product.remove(_product[i]);
}
notifyListeners();
}
}