Flutter ScrollPhysics.shouldAcceptUserOffset has no influence on the scrolling behavior

Viewed 217

I have a NestedScrollView with a CustomScrollView as a child.

For the CustomScrollview I would like to define a scroll physics that only shows an overscroll behavior at the bottom. If an overscroll occurs at the top, the drag should be passed on to the parent scrollable (NestedScrollView).

I tried to achieve this behavior by setting the acceptUserOffset value. Unfortunately, this method does not seem to be constantly called up. How do I force the ScrollPhysics to update (without going through a StatefullWidget)?

Here is the implementation of the inner ScrollPhysics:

import 'package:flutter/cupertino.dart';

class InnerScrollPhysics extends BouncingScrollPhysics {

  bool _overscroll = false;

  InnerScrollPhysics({ScrollPhysics parent,}) : super(parent: parent);

  @override
  InnerScrollPhysics applyTo(ScrollPhysics ancestor) {
    return InnerScrollPhysics(parent: buildParent(ancestor));
  }

  @override
  bool shouldAcceptUserOffset(ScrollMetrics position){
    return !_overscroll; //This does not prevent the scrollable from scrolling :(
    //super.shouldAcceptUserOffset(position);
  }

  @override
  bool get allowImplicitScrolling => false;

  @override
  double get minFlingVelocity => super.minFlingVelocity;

  @override double applyBoundaryConditions(ScrollMetrics position, double value) {

    if (value < position.pixels && position.pixels <= position.minScrollExtent) { // underscroll
      _overscroll = true;
      return value - position.pixels;
    }
    if (value < position.minScrollExtent && position.minScrollExtent < position.pixels) {// hit top edge
      _overscroll = true;
      return value - position.minScrollExtent;
    }

    //Else: no overscroll -> behave as usual
    _overscroll = false;
    return 0;
  }
}
0 Answers
Related