Skip to content

Commit eda3167

Browse files
ng1905goderbauer
ng1905
authored andcommitted
Fix ScrollOffset calculation when childCount is null (flutter#17722)
1 parent cc4eeb1 commit eda3167

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ Fredrik Simón <[email protected]>
2222
Ali Bitek <[email protected]>
2323
Tetsuhiro Ueda <[email protected]>
2424
Dan Field <[email protected]>
25+
Noah Groß <[email protected]>

packages/flutter/lib/src/widgets/sliver.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,13 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
779779
});
780780
}
781781

782-
double _extrapolateMaxScrollOffset(
782+
static double _extrapolateMaxScrollOffset(
783783
int firstIndex,
784784
int lastIndex,
785785
double leadingScrollOffset,
786786
double trailingScrollOffset,
787+
int childCount,
787788
) {
788-
final int childCount = this.childCount;
789-
if (childCount == null)
790-
return double.infinity;
791789
if (lastIndex == childCount - 1)
792790
return trailingScrollOffset;
793791
final int reifiedCount = lastIndex - firstIndex + 1;
@@ -803,6 +801,9 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
803801
double leadingScrollOffset,
804802
double trailingScrollOffset,
805803
}) {
804+
final int childCount = this.childCount;
805+
if (childCount == null)
806+
return double.infinity;
806807
return widget.estimateMaxScrollOffset(
807808
constraints,
808809
firstIndex,
@@ -814,6 +815,7 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
814815
lastIndex,
815816
leadingScrollOffset,
816817
trailingScrollOffset,
818+
childCount,
817819
);
818820
}
819821

packages/flutter/test/widgets/grid_view_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,30 @@ void main() {
481481
expect(find.text('12'), findsNothing);
482482
});
483483

484+
testWidgets('GridView.builder with undefined itemCount', (WidgetTester tester) async {
485+
await tester.pumpWidget(
486+
new Directionality(
487+
textDirection: TextDirection.ltr,
488+
child: new GridView.builder(
489+
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
490+
crossAxisCount: 4,
491+
),
492+
shrinkWrap: true,
493+
itemBuilder: (BuildContext context, int index) {
494+
return new Container(
495+
child: new Text('$index'),
496+
);
497+
},
498+
),
499+
),
500+
);
501+
expect(find.text('0'), findsOneWidget);
502+
expect(find.text('11'), findsOneWidget);
503+
await tester.drag(find.byType(GridView), const Offset(0.0, -300.0));
504+
await tester.pump(const Duration(milliseconds: 200));
505+
expect(find.text('13'), findsOneWidget);
506+
});
507+
484508
testWidgets('GridView cross axis layout', (WidgetTester tester) async {
485509
final Key target = new UniqueKey();
486510

0 commit comments

Comments
 (0)