Skip to content

Commit

Permalink
[scrollable_positioned_list] Fix manual scrolling accuracy. (#469)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
tarobins authored May 2, 2023
1 parent e0123ff commit cd51761
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
return LayoutBuilder(
builder: (context, constraints) {
final cacheExtent = _cacheExtent(constraints);
return GestureDetector(
onPanDown: (_) => _stopScroll(canceled: true),
excludeFromSemantics: true,
return Listener(
onPointerDown: (_) => _stopScroll(canceled: true),
child: Stack(
children: <Widget>[
PostMountCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,25 @@ void main() {
expect(find.text('Item 70'), findsOneWidget);
expect(find.text('Item 50'), findsOneWidget);
});

testWidgets(
'List positioned with 5 at top then scroll up so item 3 is at top',
(WidgetTester tester) async {
// debugPrintGestureArenaDiagnostics = true;
final itemPositionsListener = ItemPositionsListener.create();
await setUpWidgetTest(tester,
initialIndex: 5, itemPositionsListener: itemPositionsListener);

await tester.drag(
find.byType(ScrollablePositionedList), const Offset(0, 2 * itemHeight));
await tester.pumpAndSettle();

expect(
itemPositionsListener.itemPositions.value
.firstWhere((position) => position.index == 3)
.itemLeadingEdge,
0);
});
}

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

0 comments on commit cd51761

Please sign in to comment.