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.
diplomatic-quarter/lib/pages/pharmacies/compare-list.dart

37 lines
1.2 KiB
Dart

import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:flutter/material.dart';
class CompareList with ChangeNotifier {
List<PharmacyProduct> _product = [];
List<PharmacyProduct> get productListItems => _product;
void addItem(data) {
if (_product.length == 0) {
_product.add(data);
AppToast.showSuccessToast(message: 'You have added a product to the Compare list');
} else {
for (int i = 0; i < _product.length; i++) {
if (_product.length <= 4 && _product[i].id != data.id) {
_product.add(data);
AppToast.showSuccessToast(message: 'You have added a product to the Compare list');
break;
} else if(_product[i].id == data.id){
AppToast.showErrorToast(message: 'the item is already in the list');
} else if(_product.length == 4){
AppToast.showErrorToast(message: '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();
}
}