robert-luoqing / flutter_list_view

MIT License
47 stars 17 forks source link

scroll controller stops working after the owning constructor reruns #29

Closed graemep-nz closed 8 months ago

graemep-nz commented 8 months ago

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?

graemep-nz commented 8 months ago

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

graemep-nz commented 8 months ago

Found the problem, I was using a key that was changing when it wasn't supposed to be.