Commit d2a1389e authored by Adam Barth's avatar Adam Barth

Fix assert in Stocks app

When paging a scrollable list, we were trying to read the render object's size
at a time when we're not allowed to read it. Instead, encode the information
into the repaint limit, which is more correct (and faster) anyway.
parent c4faad11
......@@ -142,7 +142,7 @@ class _GridViewportElement extends VirtualViewportElement<GridViewport> {
_materializedChildBase = (materializedRowBase * _specification.columnCount).clamp(0, renderObject.virtualChildCount);
_materializedChildCount = (materializedRowLimit * _specification.columnCount).clamp(0, renderObject.virtualChildCount) - _materializedChildBase;
_repaintOffsetBase = _specification.rowOffsets[materializedRowBase];
_repaintOffsetLimit = _specification.rowOffsets[materializedRowLimit];
_repaintOffsetLimit = _specification.rowOffsets[materializedRowLimit] - containerExtent;
super.layout(constraints);
......
......@@ -170,7 +170,7 @@ class _ListViewportElement extends VirtualViewportElement<ListViewport> {
_materializedChildCount = materializedChildLimit - _materializedChildBase;
_repaintOffsetBase = _materializedChildBase * widget.itemExtent;
_repaintOffsetLimit = materializedChildLimit * widget.itemExtent;
_repaintOffsetLimit = materializedChildLimit * widget.itemExtent - containerExtent;
super.layout(constraints);
......
......@@ -69,15 +69,6 @@ abstract class VirtualViewportElement<T extends VirtualViewport> extends RenderO
}
}
double get _containerExtent {
switch (widget.scrollDirection) {
case ScrollDirection.vertical:
return renderObject.size.height;
case ScrollDirection.horizontal:
return renderObject.size.width;
}
}
void updateRenderObject() {
renderObject.virtualChildCount = widget.children.length;
......@@ -89,7 +80,7 @@ abstract class VirtualViewportElement<T extends VirtualViewport> extends RenderO
if (!renderObject.needsLayout) {
if (repaintOffsetBase != null && widget.startOffset < repaintOffsetBase)
renderObject.markNeedsLayout();
else if (repaintOffsetLimit != null && widget.startOffset + _containerExtent > repaintOffsetLimit)
else if (repaintOffsetLimit != null && widget.startOffset > repaintOffsetLimit)
renderObject.markNeedsLayout();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment