mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-18 05:05:28 +00:00
Add debug support and getMap function
This commit is contained in:
@ -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);
|
||||||
|
Reference in New Issue
Block a user