EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
626 stars 213 forks source link

How to remove an item properly? #245

Closed bizk-sato closed 1 year ago

bizk-sato commented 1 year ago

I want to remove an item from the list.

Tried these 2 options below suggested in https://github.com/EdsonBueno/infinite_scroll_pagination/issues/18 but they didn't work. I had to scroll the list manually, and then it was removed. I don't want users to scroll manually to remove an item.

Option 1

final newList = List.of(_pagingController.itemList);
newList.removeWhere(...);
_pagingController.itemList = newList;

Option 2

_pagingController.itemList.removeWhere(...);
_pagingController.notifyListeners();
tomasweigenast commented 1 year ago

Same here! @EdsonBueno

MichaelJHodge commented 1 year ago

Not sure if you've tried this yet @bizk-sato, but this works for me:

_pagingController.itemList.remove(object);

In this case the object is just a record/document that I've retrieved from firebase. Let me know if this helps!

sandrocsimas commented 1 year ago

Not sure if you've tried this yet @bizk-sato, but this works for me:

_pagingController.remove(object);

In this case the object is just a record/document that I've retrieved from firebase. Let me know if this helps!

PagingController does not have remove method, at least in version 3.2.0.

MichaelJHodge commented 1 year ago

Apologies! I meant:

_pagingController.itemList.remove(object);

I've updated my other reply.

sandrocsimas commented 1 year ago

Oh ok. I just tested it and also requires the user to scroll.

rajada1 commented 1 year ago

Please provide a code to reproduce the problem.

cofedream commented 1 year ago

I have same question, then I try this, it's work for me.

void removePageItem(E element){
  _pagingController.itemList?.remove(element);
  _pagingController.appendLastPage([]); // tigger notify
}
Coder7777 commented 1 year ago

remove

The code does not look elegant, but it works.

Thanks

AClon314 commented 1 year ago

I have same question, then I try this, it's work for me.

void removePageItem(E element){
  _pagingController.itemList?.remove(element);
  _pagingController.appendLastPage([]); // tigger notify
}

Maybe this could be better since the old method won't update the next page anymore.

void removePageItem(E element){
    controller.pagingController.itemList?.remove(element);
    controller.pagingController.appendPage(<E>[],0); // tigger notify but still can load the nextPage
  }

0 is my set initial page number, if your's is 1 then that's 1.

enchance commented 6 months ago

I want to remove an item from the list.

Tried these 2 options below suggested in #18 but they didn't work. I had to scroll the list manually, and then it was removed. I don't want users to scroll manually to remove an item.

Option 1

final newList = List.of(_pagingController.itemList);
newList.removeWhere(...);
_pagingController.itemList = newList;

Option 2

_pagingController.itemList.removeWhere(...);
_pagingController.notifyListeners();

Option 2 worked for me. Do you know of a way to make it animate instead of just suddenly disappearing?