Home > Net >  Flutter: Stop scrolling from animateTo function
Flutter: Stop scrolling from animateTo function

Time:11-09

** Question: How to stop scrolling of function animateTo? ** According to I set controller for SingleChildScrollView

SingleChildScrollView(
            padding: const EdgeInsets.all(10),
            controller: _scrollController

When I click button scroll. It will scroll down to bottom slowly but function

 _scrollController.animateTo(
            _scrollController.position.maxScrollExtent,
            curve: Curves.linear,
            duration: const Duration(milliseconds: 80000),
          );

I would like to click a button to stop the scrolling

CodePudding user response:

you can use jumpTo(), this will not have scrolling effect, jumps directly to the position:

 _scrollController.jumpTo(
            _scrollController.position.maxScrollExtent,
          );

CodePudding user response:

Declare a variable var endPos and var animDuration Replace your code's value with the following _scrollController.animateTo( endPos, curve: Curves.linear, duration: const Duration(milliseconds: animDuration), );

When you click on start alter the values to scrollController.position.maxScrollExtent and animDuration 8000.

When stop is clicked update the values as scrollController.position.pixels and animDuration as 100.

  • Related