From f058cefad20af2dfcd38e1b595dc887f64180129 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 13 Jul 2021 00:17:35 +1000 Subject: [PATCH] Fixes for double.tryParse --- lib/inventree/part.dart | 6 +++--- lib/inventree/stock.dart | 2 +- lib/widget/fields.dart | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index c0cef5dc..4cc4b127 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -199,10 +199,10 @@ class InvenTreePart extends InvenTreeModel { } // Get the number of stock on order for this Part - double get onOrder => double.tryParse(jsondata['ordering']) ?? 0; + double get onOrder => double.tryParse(jsondata['ordering'].toString()) ?? 0; // Get the stock count for this Part - double get inStock => double.tryParse(jsondata['in_stock']) ?? 0; + double get inStock => double.tryParse(jsondata['in_stock'].toString()) ?? 0; String get inStockString { @@ -214,7 +214,7 @@ class InvenTreePart extends InvenTreeModel { } // Get the number of units being build for this Part - double get building => double.tryParse(jsondata['building']) ?? 0; + double get building => double.tryParse(jsondata['building'].toString()) ?? 0; // Get the number of BOM items in this Part (if it is an assembly) int get bomItemCount => (jsondata['bom_items'] ?? 0) as int; diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index d730be74..0f03f2bf 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -344,7 +344,7 @@ class InvenTreeStockItem extends InvenTreeModel { String get serialNumber => jsondata['serial'] ?? ""; - double get quantity => double.tryParse(jsondata['quantity']) ?? 0; + double get quantity => double.tryParse(jsondata['quantity'].toString()) ?? 0; String get quantityString { diff --git a/lib/widget/fields.dart b/lib/widget/fields.dart index a1487ffc..0572f2b6 100644 --- a/lib/widget/fields.dart +++ b/lib/widget/fields.dart @@ -155,9 +155,8 @@ class QuantityField extends TextFormField { if (value != null && value.isEmpty) return L10().quantityEmpty; - double quantity = double.tryParse(value ?? '0') ?? 0; + double quantity = double.tryParse(value.toString()) ?? 0; - if (quantity == null) return L10().quantityInvalid; if (quantity <= 0) return L10().quantityPositive; if ((max != null) && (quantity > max)) return "Quantity must not exceed ${max}";