Skip to content

Instantly share code, notes, and snippets.

@alexcmgit
Last active April 11, 2021 21:40
Show Gist options
  • Save alexcmgit/6aeb841197c794946a72d1b6bcf09855 to your computer and use it in GitHub Desktop.
Save alexcmgit/6aeb841197c794946a72d1b6bcf09855 to your computer and use it in GitHub Desktop.
Smooth scroll physics. Instagram like
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