-
-
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
This file contains 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
//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