robert-luoqing / flutter_list_view

MIT License
45 stars 17 forks source link

Deleted items still wisible by tester #16

Closed krida2000 closed 1 year ago

krida2000 commented 1 year ago

I faced with issue when I remove items from FlutterListView they still visible by tester.

You can reproduce this problem by runing test in this project https://github.com/krida2000/flutter_list_view_problem.

This problem fixed by uncoment this code: image

Can wee just uncoment this code or there is a better solution?

robert-luoqing commented 1 year ago

@krida2000 Sorry for late reply. This is by design.

In flutter list view, All items will be reused even though these items is deactive. it just cached and invisible. So it can fetch via render object tree.

BTW, I have add disableCacheItems under FlutterListViewDelegate like below code. the version is 1.1.19. If you don't want cache those items[It may have a little performance impact]. please set the disableCacheItems to true

FlutterListView(
    controller: controller,
    delegate: FlutterListViewDelegate(
      (BuildContext context, int index) => Item(
        text: data[index],
        color: colors[index],
        height: heights[index],
      ),
      childCount: data.length,
      preferItemHeight: 50,
      // onItemHeight: (context) => 33
      disableCacheItems: disableCache,
    ),
  )