static _ResolvedDynamicList _listLookup()

in packages/rfw/lib/src/flutter/runtime.dart [535:574]


  static _ResolvedDynamicList _listLookup(DynamicList list, int targetEffectiveIndex, _StateResolverCallback stateResolver, _DataResolverCallback dataResolver) {
    int currentIndex = 0; // where we are in `list` (some entries of which might represent multiple values, because they are themselves loops)
    int effectiveIndex = 0; // where we are in the fully expanded list (the coordinate space in which we're aiming for `targetEffectiveIndex`)
    while ((effectiveIndex <= targetEffectiveIndex || targetEffectiveIndex < 0) && currentIndex < list.length) {
      final Object node = list[currentIndex]!;
      if (node is Loop) {
        Object inputList = node.input;
        while (inputList is! DynamicList) {
          if (inputList is BoundArgsReference) {
            inputList = _resolveFrom(inputList.arguments, inputList.parts, stateResolver, dataResolver);
          } else if (inputList is DataReference) {
            inputList = dataResolver(inputList.parts);
          } else if (inputList is BoundStateReference) {
            inputList = stateResolver(inputList.parts, inputList.depth);
          } else if (inputList is BoundLoopReference) {
            inputList = _resolveFrom(inputList.value, inputList.parts, stateResolver, dataResolver);
          } else if (inputList is Switch) {
            inputList = _resolveFrom(inputList, const <Object>[], stateResolver, dataResolver);
          } else {
            // e.g. it's a map or something else that isn't indexable
            inputList = DynamicList.empty();
          }
          assert(inputList is! _ResolvedDynamicList);
        }
        final _ResolvedDynamicList entry = _listLookup(inputList, targetEffectiveIndex >= 0 ? targetEffectiveIndex - effectiveIndex : -1, stateResolver, dataResolver);
        if (entry.result != null) {
          final Object boundResult = _bindLoopVariable(node.output, entry.result!, 0);
          return _ResolvedDynamicList(null, boundResult, null);
        }
        effectiveIndex += entry.length!;
      } else { // list[currentIndex] is not a Loop
        if (effectiveIndex == targetEffectiveIndex) {
          return _ResolvedDynamicList(null, list[currentIndex], null);
        }
        effectiveIndex += 1;
      }
      currentIndex += 1;
    }
    return _ResolvedDynamicList(list, null, effectiveIndex);
  }