flutter_pagewise
flutter_pagewise copied to clipboard
How to remove an item?
How to remove an item from the pagewise list?
For example, when an item is deleted.
Is also very interesting how we can insert manually an item on top after loading.
Shouldn't be too hard.
if you're storing the items in an array:
_items.remove(item)
, items.add(item)
Flutter handles the rest 🤔
Hi @carmas123 , any idea of when might we see this happening? 🙏
Perhaps I am confused -- but what exactly is the expected outcome here? Who is doing what? I don't think anyone is working on anything on this "issue". Can't you just modify the list and then do a setState() sort of thing to show the updated list?
The list is not accessible for manipulation so can't really do that..
P.S. This is not the swift plugin I mentioned on the OneSignal repo though @sjmcdowall 🙈 it's https://github.com/BaseflowIT/flutter-permission-handler
I tried extending the PagewiseLoadController. Seems to work
import 'package:flutter_pagewise/flutter_pagewise.dart';
class EditablePagewiseLoadController<T> extends PagewiseLoadController<T> {
EditablePagewiseLoadController({PageFuture<T> pageFuture, int pageSize}) : super(pageFuture: pageFuture, pageSize: pageSize);
void removeItem(bool Function(T item) test) {
this.loadedItems.removeWhere(test);
this.notifyListeners();
}
void addItem(T item) {
this.loadedItems.add(item);
this.notifyListeners();
}
void updateItem(bool Function(T item) test, T newItem) {
int index = this.loadedItems.indexWhere(test);
if (index >= 0) {
this.loadedItems.replaceRange(index, index + 1, [newItem]);
this.notifyListeners();
}
}
}
edit: removeItem function is from https://github.com/nruotsal/flutter_pagewise/tree/feature/remove-items
Hi @carmas123 , any idea of when might we see this happening? 🙏
I'm using another package for now
@sbJonas could you write an example how to use it? @carmas123 what plug-in are you using now?
Hi @pilotviper134,
to use the EditablePagewiseLoadController it has to be set up like the standard PagewiseLoadController
EditablePagewiseLoadController _pageLoadController = EditablePagewiseLoadController(
pageSize: pageSize,
pageFuture: (pageIndex) => fetchPageableData(pageIndex)
);
PagewiseSliverList(
itemBuilder: _itemBuilder,
pageLoadController: _pageLoadController,
),
Then the updateItem and removeItem functions can be used like this:
_pageLoadController.removeItem((item) => item['gsm'] == registration['gsm'] && item['department']['id'] == registration['department']['id']);
_pageLoadController.updateItem((item) => item.id == newItem.id, newItem);
Hope this helps
I tried extending the PagewiseLoadController. Seems to work
import 'package:flutter_pagewise/flutter_pagewise.dart'; class EditablePagewiseLoadController<T> extends PagewiseLoadController<T> { EditablePagewiseLoadController({PageFuture<T> pageFuture, int pageSize}) : super(pageFuture: pageFuture, pageSize: pageSize); void removeItem(bool Function(T item) test) { this.loadedItems.removeWhere(test); this.notifyListeners(); } void addItem(T item) { this.loadedItems.add(item); this.notifyListeners(); } void updateItem(bool Function(T item) test, T newItem) { int index = this.loadedItems.indexWhere(test); if (index >= 0) { this.loadedItems.replaceRange(index, index + 1, [newItem]); this.notifyListeners(); } } }
edit: removeItem function is from https://github.com/nruotsal/flutter_pagewise/tree/feature/remove-items
Can u show an example how to update an item