childCount property

int childCount
override

Copied from SliverMultiBoxAdaptorElement.childCount. The final count will be changed to take in account the last invisibile boundary item and the items taken by all intervals.

Implementation

@override
int get childCount {
  var result = estimatedChildCount;
  if (result == null) {
    // Since childCount was called, we know that we reached the end of
    // the list (as in, _build return null once), so we know that the
    // list is finite.
    // Let's do an open-ended binary search to find the end of the list
    // manually.
    var lo = 0;
    var hi = 1;
    const max = kIsWeb
        ? 9007199254740992 // max safe integer on JS (from 0 to this number x != x+1)
        : ((1 << 63) - 1);
    while (renderObject._animatedBuild(this, hi - 1, true) != null) {
      lo = hi - 1;
      if (hi < max ~/ 2) {
        hi *= 2;
      } else if (hi < max) {
        hi = max;
      } else {
        throw FlutterError(
            'Could not find the number of children in ${widget.delegate}.\n'
            'The childCount getter was called (implying that the delegate\'s builder returned null '
            'for a positive index), but even building the child with index $hi (the maximum '
            'possible integer) did not return null. Consider implementing childCount to avoid '
            'the cost of searching for the final child.');
      }
    }
    while (hi - lo > 1) {
      final mid = (hi - lo) ~/ 2 + lo;
      if (renderObject._animatedBuild(this, mid - 1, true) == null) {
        hi = mid;
      } else {
        lo = mid;
      }
    }
    result = lo;
  }
  assert(result != null);
  //""""""""""""""""""""""""""""""""""""""""""""""""""""""
  return result + 1 + renderObject._intervals.itemCountAdjustment;
  //""""""""""""""""""""""""""""""""""""""""""""""""""""""
}