Last active
April 11, 2021 21:40
-
-
Save alexcmgit/6aeb841197c794946a72d1b6bcf09855 to your computer and use it in GitHub Desktop.
Smooth scroll physics. Instagram like
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class SmoothScrollPhysics extends ScrollPhysics { | |
const SmoothScrollPhysics({ScrollPhysics parent}) : super(parent: parent); | |
@override | |
SmoothScrollPhysics applyTo(ScrollPhysics ancestor) { | |
return SmoothScrollPhysics(parent: buildParent(ancestor)); | |
} | |
@override | |
Simulation createBallisticSimulation( | |
ScrollMetrics position, double velocity) { | |
final tolerance = this.tolerance; | |
if ((velocity.abs() < tolerance.velocity) || | |
(velocity > 0.0 && position.pixels >= position.maxScrollExtent) || | |
(velocity < 0.0 && position.pixels <= position.minScrollExtent)) { | |
return null; | |
} | |
return ClampingScrollSimulation( | |
position: position.pixels, | |
velocity: velocity, | |
friction: 0.005, // <--- HERE | |
tolerance: tolerance, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment