diff --git a/packages/flutter/lib/src/widgets/nested_scroll_view.dart b/packages/flutter/lib/src/widgets/nested_scroll_view.dart index 2850847bed1..99beefd6cad 100644 --- a/packages/flutter/lib/src/widgets/nested_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/nested_scroll_view.dart @@ -1344,6 +1344,7 @@ class _NestedScrollPosition extends ScrollPosition implements ScrollActivityDele @override void goIdle() { beginActivity(IdleScrollActivity(this)); + coordinator.updateUserScrollDirection(ScrollDirection.idle); } // This is called by activities when they finish their work and want to go diff --git a/packages/flutter/test/widgets/nested_scroll_view_test.dart b/packages/flutter/test/widgets/nested_scroll_view_test.dart index af4af7a3faf..4f085c4c41e 100644 --- a/packages/flutter/test/widgets/nested_scroll_view_test.dart +++ b/packages/flutter/test/widgets/nested_scroll_view_test.dart @@ -120,6 +120,59 @@ Widget buildTest({ } void main() { + testWidgets('ScrollDirection test', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/107101 + final List receivedResult = []; + const List expectedReverseResult = [ScrollDirection.reverse, ScrollDirection.idle]; + const List expectedForwardResult = [ScrollDirection.forward, ScrollDirection.idle]; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: NotificationListener( + onNotification: (UserScrollNotification notification) { + if (notification.depth != 1) { + return true; + } + receivedResult.add(notification.direction); + return true; + }, + child: NestedScrollView( + headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) => [ + const SliverAppBar( + expandedHeight: 250.0, + pinned: true, + ), + ], + body: ListView.builder( + padding: const EdgeInsets.all(8), + itemCount: 30, + itemBuilder: (BuildContext context, int index) { + return SizedBox( + height: 50, + child: Center(child: Text('Item $index')), + ); + }, + ), + ), + ), + ), + )); + + // Fling down to trigger ballistic activity + await tester.fling(find.text('Item 3'), const Offset(0.0, -250.0), 10000.0); + await tester.pumpAndSettle(); + + expect(receivedResult, expectedReverseResult); + + receivedResult.clear(); + + // Drag forward, without ballistic activity + await tester.drag(find.text('Item 29'), const Offset(0.0, 20.0)); + await tester.pump(); + + expect(receivedResult, expectedForwardResult); + }); + testWidgets('NestedScrollView respects clipBehavior', (WidgetTester tester) async { Widget build(NestedScrollView nestedScrollView) { return Localizations(