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.xIndex < 0 || (maxXIndex != null && vicinity.xIndex > maxXIndex!)) {
    return null;
  }
  if (vicinity.yIndex < 0 || (maxYIndex != null && vicinity.yIndex > maxYIndex!)) {
    return null;
  }

  Widget? child;
  try {
    child = builder(context, vicinity);
  } catch (exception, stackTrace) {
    child = _createErrorWidget(exception, stackTrace);
  }
  if (child == null) {
    return null;
  }
  if (addRepaintBoundaries) {
    child = RepaintBoundary(child: child);
  }
  if (addAutomaticKeepAlives) {
    child = AutomaticKeepAlive(child: _SelectionKeepAlive(child: child));
  }
  return child;
}