getByPath<T> method
the path is a array of path nodes
Implementation
T getByPath<T>(List<dynamic> path, {dynamic def}) {
try {
var key = path.removeAt(0);
if (path.isEmpty) {
return get<T>(key, def: def);
} else {
if (path[0] is int) {
var index = path.removeAt(0) as int;
var valueKey = get<dynamic>(key);
var valueIndex = valueKey.get<dynamic>(index);
if ((valueIndex is ModelLess || valueIndex is ModelLessArray) &&
path.isNotEmpty) {
return valueIndex.getByPath<dynamic>(path, def: def);
}
return valueIndex as T;
}
return get<ModelLess>(key).getByPath<T>(path, def: def);
}
} catch (e) {
Console.e(e);
if (T == String && def == null) {
return "" as T;
}
return def as T;
}
}