contentExtent property
double?
get
contentExtent
The laid-out content length along the scroll axis, including sliver padding.
Unlike extentTotal, this can be smaller than viewportDimension. Lazy lists may report an estimate until their last child is laid out.
Read after layout. Returns null before content dimensions are available, when detached, or when the viewport type is unsupported. Supports sliver viewports and single-child box viewports without enabling shrink wrapping.
Implementation
double? get contentExtent {
final targetContext = context.notificationContext;
if (!hasContentDimensions || targetContext == null || !targetContext.mounted) return null;
final root = targetContext.findRenderObject();
if (root == null || !root.attached) return null;
// Stop at this scrollable's viewport rather than inspecting nested scrollables.
RenderAbstractViewport? viewport;
void findViewport(RenderObject object) {
if (object is RenderAbstractViewport) {
viewport = object;
return;
}
object.visitChildren((child) {
if (viewport == null) findViewport(child);
});
}
findViewport(root);
final target = viewport;
if (target is RenderViewportBase) {
if (!identical(target.offset, this) || !target.hasSize) {
return null;
}
var extent = 0.0;
for (var child = target.firstChild; child != null; child = target.childAfter(child)) {
final geometry = child.geometry;
if (geometry == null) {
return null;
}
extent += geometry.scrollExtent;
}
return extent;
}
if (target case final RenderObjectWithChildMixin<RenderBox> boxViewport) {
final child = boxViewport.child;
if (child == null) {
return 0.0;
}
if (!child.hasSize) {
return null;
}
return axis == .vertical ? child.size.height : child.size.width;
}
return null;
}