build method

  1. @override
Widget? build(
  1. BuildContext context,
  2. covariant ChildVicinity vicinity
)
override

Returns the child with the given ChildVicinity, which is described in terms of x and y indices.

Subclasses must implement this function and will typically wrap their children in RepaintBoundary widgets.

The values returned by this method are cached. To indicate that the widgets have changed, a new delegate must be provided, and the new delegate's shouldRebuild method must return true. Alternatively, calling notifyListeners will allow the same delegate to be used.

Implementation

@override
Widget? build(BuildContext context, ChildVicinity vicinity) {
  // If we have exceeded explicit upper bounds, return null.
  if (vicinity.yIndex < 0 || vicinity.yIndex >= children.length) {
    return null;
  }
  if (vicinity.xIndex < 0 || vicinity.xIndex >= children[vicinity.yIndex].length) {
    return null;
  }

  Widget child = children[vicinity.yIndex][vicinity.xIndex];
  if (addRepaintBoundaries) {
    child = RepaintBoundary(child: child);
  }
  if (addAutomaticKeepAlives) {
    child = AutomaticKeepAlive(child: _SelectionKeepAlive(child: child));
  }
  return child;
}