BouncingScrollSimulation constructor
Creates a simulation group for scrolling on iOS, with the given parameters.
The position and velocity arguments must use the same units as will be expected from the x and dx methods respectively (typically logical pixels and logical pixels per second respectively).
The leading and trailing extents must use the unit of length, the same unit as used for the position argument and as expected from the x method (typically logical pixels).
The units used with the provided SpringDescription must similarly be
consistent with the other arguments. A default set of constants is used
for the spring
description if it is omitted; these defaults assume
that the unit of length is the logical pixel.
Implementation
BouncingScrollSimulation({
@required double position,
@required double velocity,
@required this.leadingExtent,
@required this.trailingExtent,
@required this.spring,
Tolerance tolerance = Tolerance.defaultTolerance,
}) : assert(position != null),
assert(velocity != null),
assert(leadingExtent != null),
assert(trailingExtent != null),
assert(leadingExtent <= trailingExtent),
assert(spring != null),
super(tolerance: tolerance) {
if (position < leadingExtent) {
_springSimulation = _underscrollSimulation(position, velocity);
_springTime = double.negativeInfinity;
} else if (position > trailingExtent) {
_springSimulation = _overscrollSimulation(position, velocity);
_springTime = double.negativeInfinity;
} else {
_frictionSimulation = FrictionSimulation(0.135, position, velocity);
final double finalX = _frictionSimulation.finalX;
if (velocity > 0.0 && finalX > trailingExtent) {
_springTime = _frictionSimulation.timeAtX(trailingExtent);
_springSimulation = _overscrollSimulation(
trailingExtent,
math.min(_frictionSimulation.dx(_springTime), maxSpringTransferVelocity),
);
assert(_springTime.isFinite);
} else if (velocity < 0.0 && finalX < leadingExtent) {
_springTime = _frictionSimulation.timeAtX(leadingExtent);
_springSimulation = _underscrollSimulation(
leadingExtent,
math.min(_frictionSimulation.dx(_springTime), maxSpringTransferVelocity),
);
assert(_springTime.isFinite);
} else {
_springTime = double.infinity;
}
}
assert(_springTime != null);
}