unset static method
dynamic
unset(
- dynamic obj,
- String fieldPath
)
Implementation
static unset(obj, String fieldPath) {
var paths = fieldPath.split('.');
var curObj = obj;
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
var nextObj;
if (i == paths.length - 1) {
if (curObj is List) {
(curObj).removeAt(int.parse(path));
} else if (curObj is Map) {
curObj.remove(path);
} else {
throw '[realtime] lodash set error';
}
} else {
if (curObj is List) {
nextObj = curObj[int.parse(path)];
curObj = nextObj;
} else if (curObj is Map) {
nextObj = curObj[path];
curObj = nextObj;
} else {
throw '[realtime] lodash set error';
}
}
}
}