adammoyle
adammoyle

Reputation: 309

How to Implement Variable Scroll Sensitivity in Flutter's PageView Based on Distance from Initial Page?

I'm looking to implement a custom scroll physics for an infinite PageView. My goal is to adjust the scrolling sensitivity dynamically based on the distance from the initial page. The behaviour I’m trying to achieve is:

class FastScrollPhysics extends PageScrollPhysics {
  const FastScrollPhysics({super.parent});

  @override
  FastScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return FastScrollPhysics(parent: buildParent(ancestor));
  }

  @override
  double applyPhysicsToUserOffset(ScrollMetrics position, double offset) {
    final double scrollMultiplier = someCalculation; // Need help here
    return offset *
        scrollMultiplier; 
  }
}

Question:

  1. How can I calculate the scrollMultiplier based on the user’s distance from the initial page?
  2. What is the best way to track the position of the user relative to the initial page so that the sensitivity changes dynamically?

Upvotes: 0

Views: 26

Answers (0)

Related Questions