Nitiphone Xayaseng
Nitiphone Xayaseng

Reputation: 25

Flutter: Stop scrolling from animateTo function

** 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

Upvotes: 0

Views: 1819

Answers (1)

Kaushik Chandru
Kaushik Chandru

Reputation: 17762

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.

Upvotes: 1

Related Questions