diff --git a/packages/flutter/lib/src/widgets/block.dart b/packages/flutter/lib/src/widgets/block.dart index 27b6431dcd..8957367acc 100644 --- a/packages/flutter/lib/src/widgets/block.dart +++ b/packages/flutter/lib/src/widgets/block.dart @@ -78,7 +78,13 @@ abstract class SliverBlockDelegate { double leadingScrollOffset, double trailingScrollOffset, ) { - return childCount * (trailingScrollOffset - leadingScrollOffset) / (lastIndex - firstIndex + 1); + final int childCount = this.childCount; + if (lastIndex == childCount - 1) + return trailingScrollOffset; + final int reifiedCount = lastIndex - firstIndex + 1; + final double averageExtent = (trailingScrollOffset - leadingScrollOffset) / reifiedCount; + final int remainingCount = childCount - lastIndex - 1; + return trailingScrollOffset + averageExtent * remainingCount; } } diff --git a/packages/flutter/test/widgets/block_test.dart b/packages/flutter/test/widgets/block_test.dart index 75c5d2cf0b..16f9131a0d 100644 --- a/packages/flutter/test/widgets/block_test.dart +++ b/packages/flutter/test/widgets/block_test.dart @@ -119,4 +119,16 @@ void main() { await tester.pumpWidget(buildBlock()); expect(key.currentState.scrollOffset, 0.0); }); + + testWidgets('SliverBlockChildListDelegate.estimateScrollOffsetExtent hits end', (WidgetTester tester) async { + SliverBlockChildListDelegate delegate = new SliverBlockChildListDelegate([ + new Container(), + new Container(), + new Container(), + new Container(), + new Container(), + ]); + + expect(delegate.estimateScrollOffsetExtent(3, 4, 25.0, 26.0), equals(26.0)); + }); }