build method

  1. @override
Widget build (BuildContext context, int index)
override

Returns the child with the given index.

Should return null if asked to build a widget with a greater index than exists. If this returns null, estimatedChildCount must subsequently return a precise non-null value.

Subclasses typically override this function and wrap their children in AutomaticKeepAlive and RepaintBoundary widgets.

Implementation

@override
Widget build(BuildContext context, int index) {
  assert(builder != null);
  if (index < 0 || (childCount != null && index >= childCount))
    return null;
  Widget child;
  try {
    child = builder(context, index);
  } catch (exception, stackTrace) {
    child = _createErrorWidget(exception, stackTrace);
  }
  if (child == null)
    return null;
  if (addRepaintBoundaries)
    child = RepaintBoundary.wrap(child, index);
  if (addSemanticIndexes) {
    final int semanticIndex = semanticIndexCallback(child, index);
    if (semanticIndex != null)
      child = IndexedSemantics(index: semanticIndex + semanticIndexOffset, child: child);
  }
  if (addAutomaticKeepAlives)
    child = AutomaticKeepAlive(child: child);
  return child;
}