flutter_slidable icon indicating copy to clipboard operation
flutter_slidable copied to clipboard

closeOnScroll not working, please look for first primary Scrollable

Open Jan-pp opened this issue 5 years ago • 4 comments

Ik have a List containing a few Cards which each contains another List (so a List of Lists). These sublists have primary set to false, so the page scrolls as one static page.

closeOnScroll looks for the first Scrollable, which is why it isn't working in my case, since the sublist containing the Slidable doesn't technically scroll because primary is set to false.

So instead of just looking for the first Scrollable, can you have it look for the first Scrollable with primary set to true? If it can't find one use the top level Scrollable.

Jan-pp avatar Jun 30 '20 15:06 Jan-pp

I changed the _addScrollingNotifierListener() to work like I described. For me it works perfectly this way because it now looks for the first Scrollable that actually scrolls.

  void _addScrollingNotifierListener() {
    if (widget.closeOnScroll) {

      //recursively look for the first primary scrollable (physics == null means not primary)
      //if no primary scrollable is found use the top found Scrollable

      BuildContext nextContext = context;

      while (true) {       
        final nextScrollable = Scrollable.of(nextContext);

        if (nextScrollable == null)
          break;
        
        _scrollPosition = nextScrollable.position ?? _scrollPosition;

        if (nextScrollable.widget.physics == null || nextScrollable.position == null)
          nextContext = nextScrollable.context; //by setting this the next loop will look for a higher Scrollable
        else
          break;
      }
      _scrollPosition?.isScrollingNotifier.addListener(_isScrollingListener);
    }
  }

Would you like to try this out?

Jan-pp avatar Jul 02 '20 10:07 Jan-pp

Interesting use case! I will keep it in mind for my refactoring.

letsar avatar Nov 08 '20 20:11 letsar

Can you verify this use case is still possible in the 1.0 version?

letsar avatar Jul 20 '21 19:07 letsar

I haven't used Flutter for a while so it's hard for me to give it a quick try. I take it you have tried the list of lists approach yourself?

I'm using a different account these days by the way (this one).

Janneman84 avatar Jul 21 '21 17:07 Janneman84