The question is difficult to understand due to machine translation. Sorry.
I am looking for a way to actively stop the scrolling of a ScrollView in Flutter.
The action is Scroll state -> multiple touches -> idle scrolling I'm thinking of a flow like this.
The Listener widget is already able to acquire multiple touches I can also get the scrolling state with NotificationListener, but I am not able to stop it from here. but we are not able to stop it from here.
In the ScrollPosition documentation I have confirmed that there is a method called beginActivity(ScrollActivity? newActivity), but I am not sure how to implement this method. I am not sure how to implement this method.
I would appreciate it if someone could help me solve this problem.
return Scaffold(
body: NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification scrollNotification) {
if(_touchCount >= 2)
{
setState(() {
//We plan to include a scroll stop process in this.
});
}
return true;
},
child: Listener(
onPointerDown: incrementEnter,
onPointerUp: incrementExit,
onPointerCancel: incrementExit,
child: SingleChildScrollView(
),
),
),
);
CodePudding user response:
You're going to need to create a ScrollController
which should be owned by State
and passed into your SingleChildScrollView
.
Subclass ScrollController
and add a method to call or a member to set when your touch count threshold is met to tell the controller to stop. By stop I mean override createScrollPosition
and return the old position if that stop flag is true otherwise have the override return super.createScrollPosition
.
Just to be clear, listening to the ScrollNotification
and setState
is unnecessary. All the logic should be in the scroll controller.