2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-18 13:15:31 +00:00

Add debug support and getMap function

This commit is contained in:
Oliver Walters
2023-04-21 20:24:21 +10:00
parent 27f2fd4826
commit bfb582efb2

View File

@ -76,16 +76,29 @@ class InvenTreeModel {
// If a subKey is specified, we need to dig deeper into the JSON data // If a subKey is specified, we need to dig deeper into the JSON data
if (subKey.isNotEmpty) { 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<String, dynamic>; data = (data[subKey] ?? {}) as Map<String, dynamic>;
} }
if (data.containsKey(key)) { if (data.containsKey(key)) {
return data[key]; return data[key];
} else { } else {
debug("JSON data does not contain key '$key' (subKey '${subKey}')");
return backup; return backup;
} }
} }
// Helper function to get sub-map from JSON data
Map<String, dynamic> getMap(String key, {Map<String, dynamic> backup = const {}, String subKey = ""}) {
dynamic value = getValue(key, backup: backup, subKey: subKey);
return value as Map<String, dynamic>;
}
// Helper function to get string value from JSON data // Helper function to get string value from JSON data
String getString(String key, {String backup = "", String subKey = ""}) { String getString(String key, {String backup = "", String subKey = ""}) {
dynamic value = getValue(key, backup: backup, subKey: subKey); dynamic value = getValue(key, backup: backup, subKey: subKey);