Unverified Commit 659ba386 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix SliverGridRegularTileLayout.computeMaxScrollOffset for 0 children (#123348)

Fix SliverGridRegularTileLayout.computeMaxScrollOffset for 0 children
parent bb02b52b
......@@ -225,6 +225,11 @@ class SliverGridRegularTileLayout extends SliverGridLayout {
@override
double computeMaxScrollOffset(int childCount) {
if (childCount == 0) {
// There are no children in the grid. The max scroll offset should be
// zero.
return 0.0;
}
final int mainAxisCount = ((childCount - 1) ~/ crossAxisCount) + 1;
final double mainAxisSpacing = mainAxisStride - childMainAxisExtent;
return mainAxisStride * mainAxisCount - mainAxisSpacing;
......
......@@ -1294,6 +1294,55 @@ void main() {
expect(firstTapped, 0);
expect(secondTapped, 1);
});
testWidgets('SliverGridRegularTileLayout.computeMaxScrollOffset handles 0 children', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/59663
final ScrollController controller = ScrollController();
// SliverGridDelegateWithFixedCrossAxisCount
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: CustomScrollView(
controller: controller,
slivers: <Widget>[
SliverGrid.builder(
itemCount: 0,
itemBuilder: (_, __) => Container(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 10,
childAspectRatio: 2.1,
),
),
],
),
),
));
// Verify correct scroll extent
expect(controller.position.maxScrollExtent, 0.0);
// SliverGridDelegateWithMaxCrossAxisExtent
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: CustomScrollView(
controller: controller,
slivers: <Widget>[
SliverGrid.builder(
itemCount: 0,
itemBuilder: (_, __) => Container(),
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 30,
),
),
],
),
),
));
// Verify correct scroll extent
expect(controller.position.maxScrollExtent, 0.0);
});
}
bool isRight(Offset a, Offset b) => b.dx > a.dx;
......
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