Remove floating-point errors from ScrollableWidgetList
We now compute which items to show using integers instead of floating point, avoiding rounding errors.
This commit is contained in:
parent
14f3f58cd9
commit
c696c21aa5
@ -338,8 +338,6 @@ class Block extends Component {
|
|||||||
/// widget when you have a large number of children or when you are concerned
|
/// widget when you have a large number of children or when you are concerned
|
||||||
// about offscreen widgets consuming resources.
|
// about offscreen widgets consuming resources.
|
||||||
abstract class ScrollableWidgetList extends Scrollable {
|
abstract class ScrollableWidgetList extends Scrollable {
|
||||||
static const _kEpsilon = .0000001;
|
|
||||||
|
|
||||||
ScrollableWidgetList({
|
ScrollableWidgetList({
|
||||||
Key key,
|
Key key,
|
||||||
ScrollDirection scrollDirection: ScrollDirection.vertical,
|
ScrollDirection scrollDirection: ScrollDirection.vertical,
|
||||||
@ -445,24 +443,13 @@ abstract class ScrollableWidgetList extends Scrollable {
|
|||||||
if (paddedScrollOffset < scrollBehavior.minScrollOffset) {
|
if (paddedScrollOffset < scrollBehavior.minScrollOffset) {
|
||||||
// Underscroll
|
// Underscroll
|
||||||
double visibleExtent = _containerExtent + paddedScrollOffset;
|
double visibleExtent = _containerExtent + paddedScrollOffset;
|
||||||
itemShowCount = (visibleExtent / itemExtent).round() + 1;
|
itemShowCount = (visibleExtent / itemExtent).ceil();
|
||||||
viewportOffset = _toOffset(paddedScrollOffset);
|
viewportOffset = _toOffset(paddedScrollOffset);
|
||||||
} else {
|
} else {
|
||||||
itemShowCount = (_containerExtent / itemExtent).ceil();
|
itemShowCount = (_containerExtent / itemExtent).ceil() + 1;
|
||||||
double alignmentDelta = (-paddedScrollOffset % itemExtent);
|
itemShowIndex = (paddedScrollOffset / itemExtent).floor();
|
||||||
double drawStart = paddedScrollOffset;
|
viewportOffset = _toOffset(paddedScrollOffset - itemShowIndex * itemExtent);
|
||||||
if (alignmentDelta != 0.0) {
|
itemShowIndex %= itemCount; // Wrap index for when itemWrap is true.
|
||||||
alignmentDelta -= itemExtent;
|
|
||||||
itemShowCount += 1;
|
|
||||||
drawStart += alignmentDelta;
|
|
||||||
viewportOffset = _toOffset(-alignmentDelta);
|
|
||||||
}
|
|
||||||
if (itemCount > 0) {
|
|
||||||
// floor(epsilon) = 0, floor(-epsilon) = -1, so:
|
|
||||||
if (drawStart.abs() < _kEpsilon)
|
|
||||||
drawStart = 0.0;
|
|
||||||
itemShowIndex = (drawStart / itemExtent).floor() % itemCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user