Skip to content

ScrollableState.setCanDrag should not contradict with scroll physics #82391

@nt4f04uNd

Description

@nt4f04uNd

Currently, because ScrollableState.setCanDrag doesn't check whether it complies with ScrollPhysics.shouldAcceptUserOffset, it's possible that user of ScrollableState doesn't check whether it can be set to true or false and thus ignores scroll physics by mistake - which is what happens to NestedScrollView, which forgets to do exactly this #45619

void updateCanDrag(double totalExtent) {
context.setCanDrag(totalExtent > (viewportDimension - maxScrollExtent) || minScrollExtent != maxScrollExtent);
}

I propose that we force users of the ScrollableState to check the physics before they apply their own conditions with such assert (or something similar)

assert(
  _physics == null || newCanDrag == _physics!.shouldAcceptUserOffset(position),
  'When scrollable has physics, canDrag should be equal to shouldAcceptUserOffset result',
);

cc @Hixie

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions