Open edwardaux opened 3 years ago
I'm have a same problem here. 🤔
But my error show inside tests.
My mixin:
mixin ScrollToMixin {
void scrollTo(int index, ItemScrollController itemScrollController) {
itemScrollController.scrollTo(
index: index,
alignment: 0,
curve: Curves.easeIn,
duration: const Duration(milliseconds: 1500),
);
}
}
getting same error.
+1
I am also facing the same issue.
Problem description
Using
^0.2.0-nullsafety.0
of scrollable_positioned_list inside a stateful widget that displays an overlay, I constantly get this error every time the overlay gets re-created:Steps to reproduce
My particular use case is a stateful widget that is offering typeahead suggestions (somewhat like what Spotlight does on macOS) using an
Overlay
.The underlying problem is a combo of a few things:
_itemScrollController
instance variableItemScrollController
instance to_itemScrollController
in my widget'sinitState()
functionOverlay
gets recreated_itemScrollController
object is passed into theScrollablePositionedList
when the overlay gets rebuiltUnder the covers, though, the scroll controller doesn't like it if it is being re-attached to a new widget when it had previously been attached to another one.
Expected behavior
Well, I wasn't expecting a crash... however, if you think about the above scenario, I'm not entirely sure how I'd expect this library to be able to cope with re-attaching.
Not sure if there's an underlying bug here where this package could handle this scenario a bit better, but I'm raising this ticket as a way of sharing what the underlying problem is and how to resolve (in case other developers stumble across the same problem).
Steps to resolve
While technically 100% accurate, the stack trace isn't particularly helpful in terms of figuring out /why/ it is in this state. My "fix" was relatively simple... just before re-creating the
Overlay
, I just create a new scroll controller. eg: