flutter_slidable
flutter_slidable copied to clipboard
closeOnScroll not working, please look for first primary Scrollable
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.
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?
Interesting use case! I will keep it in mind for my refactoring.
Can you verify this use case is still possible in the 1.0 version?
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).