deleteFieldOfObject method
Deletes a field of an object in the current opened box
Returns a Future
Implementation
Future<bool> deleteFieldOfObject() async {
final viewState = _hiveViewState;
final currentBox = viewState.currentOpenedBox!;
var boxValue = viewState.selectedBoxValue!;
final indices = viewState.objectNestedIndices!;
final firstIndexMap = indices.first;
final lastIndexMap = indices.last;
var refObj =
boxValue[firstIndexMap.keys.single][firstIndexMap.values.single];
if (indices.length == 1) {
refObj.clear();
} else {
for (var indexMap in indices..removeAt(0)) {
if (indexMap == lastIndexMap) {
refObj[indexMap.values.single].clear();
} else if (indexMap.keys.single == -1) {
refObj = refObj[indexMap.values.single];
} else {
refObj = refObj[indexMap.keys.single][indexMap.values.single];
}
}
}
final replacementObject = boxValue[firstIndexMap.keys.single];
return await _updateBoxWithObject(
currentBox,
firstIndexMap.keys.single,
replacementObject,
);
}