Fix SliverGridRegularTileLayout.computeMaxScrollOffset for 0 children (#123348)
Fix SliverGridRegularTileLayout.computeMaxScrollOffset for 0 children
This commit is contained in:
parent
bb02b52bd8
commit
659ba386f6
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user