Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Created March 9, 2021 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makoConstruct/d069651b51d573a7a94bae13c8730656 to your computer and use it in GitHub Desktop.
Save makoConstruct/d069651b51d573a7a94bae13c8730656 to your computer and use it in GitHub Desktop.
a scrollphysics that allows the user to pull the content down so that it is within reach from the bottom of the phone
//a scrollphysics that allows the user to pull the content down so that it is within reach from the bottom of the phone
class _ExtraScrollPhysics extends AlwaysScrollableScrollPhysics {
final double extra;
_ExtraScrollPhysics({this.reach, ScrollPhysics parent})
: super(parent: parent);
ScrollMetrics expandScrollMetrics(ScrollMetrics extant) {
return FixedScrollMetrics(
pixels: extant.pixels,
axisDirection: extant.axisDirection,
minScrollExtent:
min(extant.minScrollExtent, -extra),
maxScrollExtent: extant.maxScrollExtent,
viewportDimension: extant.viewportDimension,
);
}
_ExtraScrollPhysics applyTo(ScrollPhysics ancestor) {
return _ExtraScrollPhysics(parent: buildParent(ancestor), reach: reach);
}
@override
double applyPhysicsToUserOffset(ScrollMetrics position, double offset) {
return super
.applyPhysicsToUserOffset(expandScrollMetrics(position), offset);
}
@override
bool shouldAcceptUserOffset(ScrollMetrics position) {
return super.shouldAcceptUserOffset(expandScrollMetrics(position));
}
@override
double adjustPositionForNewDimensions({
ScrollMetrics oldPosition,
ScrollMetrics newPosition,
bool isScrolling,
double velocity,
}) {
return super.adjustPositionForNewDimensions(
oldPosition: expandScrollMetrics(oldPosition),
newPosition: expandScrollMetrics(newPosition),
isScrolling: isScrolling,
velocity: velocity);
}
@override
double applyBoundaryConditions(ScrollMetrics position, double value) {
// return min(
// value - minAllowance,
// );
return super.applyBoundaryConditions(
expandScrollMetrics(position),
value,
);
}
@override
Simulation createBallisticSimulation(
ScrollMetrics position, double velocity) {
return super
.createBallisticSimulation(expandScrollMetrics(position), velocity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment