From 338251daffc9b5cadfe4e8bb0389566b71d783bd Mon Sep 17 00:00:00 2001 From: darCavalier11 Date: Tue, 30 Aug 2022 16:04:42 +0530 Subject: [PATCH] support for double and int price type --- lib/models/printable_receipt.dart | 42 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/models/printable_receipt.dart b/lib/models/printable_receipt.dart index 46ff4dc..3ea44b6 100644 --- a/lib/models/printable_receipt.dart +++ b/lib/models/printable_receipt.dart @@ -8,13 +8,12 @@ class PrintableCharges { factory PrintableCharges.fromJson(Map json) { return PrintableCharges( name: json['name'] ?? '-', - value: json['value'] == null ? 0 : (json['value'] as int).paisaToRupee, + value: json['value'].runtimeType == int + ? (json['value'] as int).paisaToRupee + : json['value'], ); } - @override - String toString() => 'PrintableCharges(name: $name, value: $value)'; - Map toJson() { return { 'name': name, @@ -22,12 +21,8 @@ class PrintableCharges { }; } - factory PrintableCharges.fromMap(Map map) { - return PrintableCharges( - name: map['name'] ?? '', - value: map['value']?.toDouble() ?? 0.0, - ); - } + @override + String toString() => 'PrintableCharges(name: $name, value: $value)'; } class PrintableOrderItems { @@ -45,9 +40,17 @@ class PrintableOrderItems { factory PrintableOrderItems.fromJson(Map json) { return PrintableOrderItems( name: json['name'] ?? '-', - total: json['total'] == null ? 0 : (json['total'] as int).paisaToRupee, + total: json['total'] != null + ? json['total'].runtimeType == int + ? (json['total'] as int).paisaToRupee + : json['total'] + : 0, quantity: json['quantity'] ?? 0, - price: json['price'] == null ? 0 : (json['price'] as int).paisaToRupee, + price: json['price'] != null + ? json['price'].runtimeType == int + ? (json['price'] as int).paisaToRupee + : json['price'] + : 0, ); } @@ -105,11 +108,16 @@ class PrintableReceipt { : (json['other_charges'] as List) .map((e) => PrintableCharges.fromJson(e)) .toList(), - discount: - json['discount'] == null ? 0 : (json['discount'] as int).paisaToRupee, - orderTotal: json['order_total'] == null - ? 0 - : (json['order_total'] as int).paisaToRupee, + discount: json['discount'] != null + ? json['discount'].runtimeType == int + ? (json['discount'] as int).paisaToRupee + : json['discount'] + : 0, + orderTotal: json['order_total'] != null + ? json['order_total'].runtimeType == int + ? (json['order_total'] as int).paisaToRupee + : json['order_total'] + : 0, printerId: json['printer_id'] ?? '', orderId: json['order_id'] ?? '-', );