Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit cd51761

Browse files
authored
[scrollable_positioned_list] Fix manual scrolling accuracy. (#469)
* [scrollable_positioned_list] Fix manual scrolling accuracy. Previously the GestureDetector caused the ScrollablePositionedList to loose a few pixels when scrolling started. Part of work on #41. * Fix formatting
1 parent e0123ff commit cd51761

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,8 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
338338
return LayoutBuilder(
339339
builder: (context, constraints) {
340340
final cacheExtent = _cacheExtent(constraints);
341-
return GestureDetector(
342-
onPanDown: (_) => _stopScroll(canceled: true),
343-
excludeFromSemantics: true,
341+
return Listener(
342+
onPointerDown: (_) => _stopScroll(canceled: true),
344343
child: Stack(
345344
children: <Widget>[
346345
PostMountCallback(

packages/scrollable_positioned_list/test/scrollable_positioned_list_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,25 @@ void main() {
22662266
expect(find.text('Item 70'), findsOneWidget);
22672267
expect(find.text('Item 50'), findsOneWidget);
22682268
});
2269+
2270+
testWidgets(
2271+
'List positioned with 5 at top then scroll up so item 3 is at top',
2272+
(WidgetTester tester) async {
2273+
// debugPrintGestureArenaDiagnostics = true;
2274+
final itemPositionsListener = ItemPositionsListener.create();
2275+
await setUpWidgetTest(tester,
2276+
initialIndex: 5, itemPositionsListener: itemPositionsListener);
2277+
2278+
await tester.drag(
2279+
find.byType(ScrollablePositionedList), const Offset(0, 2 * itemHeight));
2280+
await tester.pumpAndSettle();
2281+
2282+
expect(
2283+
itemPositionsListener.itemPositions.value
2284+
.firstWhere((position) => position.index == 3)
2285+
.itemLeadingEdge,
2286+
0);
2287+
});
22692288
}
22702289

22712290
bool collectSemanticNodes(SemanticsNode root, List<SemanticsNode> nodes) {

0 commit comments

Comments
 (0)