findNextNodeById method

CNode? findNextNodeById(
  1. CNode parent,
  2. String? idToFind
)

Implementation

CNode? findNextNodeById(CNode parent, String? idToFind) {
  if (parent.children == null || idToFind == null) {
    return null;
  }

  int index = -1;
  for (var i = 0; i < parent.children!.length; i++) {
    if (parent.children![i].id == idToFind) {
      index = i;
      break;
    }
  }

  if (index != -1 && index < parent.children!.length - 1) {
    return parent.children![index + 1];
  } else {
    return null;
  }
}