scroll controller stops working after the owning constructor reruns
Closed this issue · 2 comments
I create a ScrollController in initState and pass it in a call to the FlutterListView constructor like this
FlutterListView(
key: ObjectKey(clientListViewItemBuilder),
controller: flutterListViewScrollController,
cacheExtent: 20,
delegate: FlutterListViewDelegate(
(BuildContext context, int index) {
return clientListViewItemBuilder!(context, index);
},
childCount: maxItemCountCallback!(),
)
),
and this is inside the build method of a class called say ClassX. The scroll controller works correctly initially until the constructor of ClassX reruns. The following sequence then happens
///////////////////////////////////
ClassX constructor runs
didUpdateWidget runs
the build method starts
the scroll controller gets attached to the listView
a long list of unMount functions get called by the dart framework
"a" scroll controller gets detached from "a" listview (by one of the unMount functions)
the build method ends
///////////////////////////////
now the scrollController no longer works.
If I create a brand new ScrollController in didUpdateWidget and pass that to the FlutterListView constructor, the new scroll controller keeps working. I don't really want to do this and surely I shouldn't have to. Does this seem like a bug in FlutterListView? Why does it think it needs to do a detach?
I'm unable to reproduce this problem with a simple app (attached) but my real app is more complex.
Here's the simple example that works correctly. It needs flutter_list_view from latest github
test_flutter_listview.zip
Found the problem, I was using a key that was changing when it wasn't supposed to be.