class DiscountByWeight { String? id; double weight; double discount; DiscountByWeight({this.id, this.weight = 0, this.discount = 0}); factory DiscountByWeight.fromMap(Map map, String id) { return DiscountByWeight( id: id, weight: (map['weight'] ?? 0).toDouble(), discount: (map['discount'] ?? 0).toDouble(), ); } Map toMap() { return { "id": id, 'weight': weight, 'discount': discount, }; } bool isChangedForEdit(DiscountByWeight discountByWeight) { return discountByWeight.weight != this.weight || discountByWeight.discount != this.discount; } }