getNextFocus method Null safety

FocusNode getNextFocus(
  1. String key
)

Implementation

FocusNode getNextFocus(String key) {
  int pos = 0;
  String nextKey;
  List<String> list = this.data.keys.toList();

  if (key == null) {
    nextKey = list.elementAt(pos);
  } else if (this.data.containsKey(key)) {
    pos = list.indexOf(key);
    if (pos < list.length - 1) {
      nextKey = list.elementAt(pos + 1);
    }
  }

  for (var i = 0; i < (list.length - 1); i++) {
    if (i > pos) {
      String k1 = list.elementAt(i);
      String k2 = list.elementAt(i + 1);

      if (this.data[k1] is YekongaForm) {
        this.data[k1].parentNextFocusNode = this.data[k2].getNextFocus(null);
      }
    }
  }

  if (nextKey != null) {
    if (this.data[nextKey] is YekongaForm) {
      return this.data[nextKey].getNextFocus(null);
    } else if (this.focusNodes.containsKey(nextKey)) {
      return this.focusNodes[nextKey];
    }
  }

  if (this.parentNextFocusNode != null) {
    return this.parentNextFocusNode;
  }

  return null;
}