From bfb582efb22aa0e9c8eb35b58a77461dcff5b035 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 21 Apr 2023 20:24:21 +1000 Subject: [PATCH] Add debug support and getMap function --- lib/inventree/model.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index ca647c64..9703ef7e 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -76,16 +76,29 @@ class InvenTreeModel { // If a subKey is specified, we need to dig deeper into the JSON data if (subKey.isNotEmpty) { + + if (!data.containsKey(subKey)) { + debug("JSON data does not contain subKey '$subKey' for key '$key'"); + return backup; + } + data = (data[subKey] ?? {}) as Map; } if (data.containsKey(key)) { return data[key]; } else { + debug("JSON data does not contain key '$key' (subKey '${subKey}')"); return backup; } } + // Helper function to get sub-map from JSON data + Map getMap(String key, {Map backup = const {}, String subKey = ""}) { + dynamic value = getValue(key, backup: backup, subKey: subKey); + return value as Map; + } + // Helper function to get string value from JSON data String getString(String key, {String backup = "", String subKey = ""}) { dynamic value = getValue(key, backup: backup, subKey: subKey);