applyBoundaryConditions method Null safety

  1. @protected
double applyBoundaryConditions(
  1. double value
)

Returns the overscroll by applying the boundary conditions.

If the given value is in bounds, returns 0.0. Otherwise, returns the amount of value that cannot be applied to pixels as a result of the boundary conditions. If the physics allow out-of-bounds scrolling, this method always returns 0.0.

The default implementation defers to the physics object's ScrollPhysics.applyBoundaryConditions.

Implementation

@protected
double applyBoundaryConditions(double value) {
  final double result = physics.applyBoundaryConditions(this, value);
  assert(() {
    final double delta = value - pixels;
    if (result.abs() > delta.abs()) {
      throw FlutterError(
        '${physics.runtimeType}.applyBoundaryConditions returned invalid overscroll value.\n'
        'The method was called to consider a change from $pixels to $value, which is a '
        'delta of ${delta.toStringAsFixed(1)} units. However, it returned an overscroll of '
        '${result.toStringAsFixed(1)} units, which has a greater magnitude than the delta. '
        'The applyBoundaryConditions method is only supposed to reduce the possible range '
        'of movement, not increase it.\n'
        'The scroll extents are $minScrollExtent .. $maxScrollExtent, and the '
        'viewport dimension is $viewportDimension.',
      );
    }
    return true;
  }());
  return result;
}