title: Flutter: how to test the scroll
body: <p>I have a ListView.builder with a ScrollController as controller:</p>
  
  <pre><code>  _buildListView(state) =&gt; ListView.builder(
          itemBuilder: (_, int index) =&gt; _draw(index, state),
          itemCount: state.count
          controller: _scrollController,
        );
  </code></pre>
  
  <p>I add a listener to the controller:</p>
  
  <pre><code>  View() {
      _scrollController.addListener(_onScroll);
    }
  </code></pre>
  
  <p>I would like to test the _onScroll function:</p>
  
  <pre><code> void _onScroll() {
      final maxScroll = _scrollController.position.maxScrollExtent;
      final currentScroll = _scrollController.position.pixels;
      if (maxScroll - currentScroll &lt;= _scrollThreshold) {
        _bloc.dispatch(Fetch());
      }
    }
  </code></pre>
  
  <p>But I don't know how can I test it. This is what I tried so far:</p>
  
  <pre><code>  testWidgets('Should test the scroll',
        (WidgetTester tester) async {
  await tester.pumpWidget(generateApp());
      await tester.pump();
      await tester.drag(find.byType(ListView), const Offset(0.0, -300));
      await tester.pump();
  ...
  
  )}
  </code></pre>
  
  <p>but it doesn't call at all that function.</p>