removeBranch method

void removeBranch({
  1. required CatalogRow row,
  2. required String locale,
  3. required List<String> path,
})

Implementation

void removeBranch({
  required CatalogRow row,
  required String locale,
  required List<String> path,
}) {
  final draft = valueDraftFor(row, locale);
  if (draft.value is! Map) {
    return;
  }
  final nextValue = cloneCatalogValue(draft.value);
  if (path.length == 1) {
    (nextValue as Map).remove(path.first);
  } else if (path.length == 2) {
    final nested = nextValue[path[0]];
    if (nested is Map) {
      nested.remove(path[1]);
    }
  }
  draft.value = nextValue;
  draft.rawText = prettyCatalogJson(draft.value);
  draft.rawError = null;
  draft.touched = true;
  _scheduleValueDraftSave(draft);
}