flutter_pagewise icon indicating copy to clipboard operation
flutter_pagewise copied to clipboard

How to remove an item?

Open lifenautjoe opened this issue 5 years ago • 10 comments

How to remove an item from the pagewise list?

For example, when an item is deleted.

lifenautjoe avatar Mar 10 '19 17:03 lifenautjoe

Is also very interesting how we can insert manually an item on top after loading.

carmas123 avatar Mar 21 '19 19:03 carmas123

Shouldn't be too hard.

if you're storing the items in an array:

_items.remove(item), items.add(item)

Flutter handles the rest 🤔

lifenautjoe avatar Mar 21 '19 19:03 lifenautjoe

Hi @carmas123 , any idea of when might we see this happening? 🙏

lifenautjoe avatar Mar 25 '19 16:03 lifenautjoe

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?

sjmcdowall avatar Mar 25 '19 20:03 sjmcdowall

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

lifenautjoe avatar Mar 25 '19 21:03 lifenautjoe

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

sbJonas avatar Jul 03 '19 11:07 sbJonas

Hi @carmas123 , any idea of when might we see this happening? 🙏

I'm using another package for now

carmas123 avatar Jul 03 '19 12:07 carmas123

@sbJonas could you write an example how to use it? @carmas123 what plug-in are you using now?

pilotviper134 avatar Nov 12 '19 18:11 pilotviper134

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

sbJonas avatar Nov 13 '19 11:11 sbJonas

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

indjec avatar Oct 08 '21 11:10 indjec