0

i am using GetX as a state management and i have a list declared inside a controller like this..

List<Chair> selectedSeats = <Chair>[].obs;

i have two methods inside to add and delete item to/from the list.

this i use to add the chair

  void addSelectedChair(Chair chair) {
    if (selectedSeats.contains(chair.chairName)) {
      return;
    } else {
      selectedSeats.add(chair);
    }
    update();
    print(chair.chairName);
  }

and this i use to delete the chair from the list..

final controller = Get.put(SeatController());


// this is how i call this method
//controller.removeSelectedChair(this.widget.customList[index].chairName);
//like controller.removeSelectedChair("C2");

  void removeSelectedChair(String chair) {
    selectedSeats.removeWhere(((item)=>item.chairName == chair));
    print(chair);
    update();
  }

but i cant get the remove to work... why isnt it removing a chair from the selectedSeats list..

here is the chair model, if its any of use..

enum ReserveState { available, reserved, selected }

class Chair {
  ReserveState reserveState;
  int rowNum;
  int cNum;
  String chairName = '';

  Chair(this.rowNum, this.cNum,this.reserveState,this.chairName);

}
Danny
  • 317
  • 4
  • 17

1 Answers1

0

try this:

selectedSeats.value.removeWhere(((item)=>item.chairName == chair));

also, it's not necessary to use an update each time, you can use the refresh method to rerender parts that depend on your array like this:

selectedSeats.refresh()

but do this if you are changing the internal value directly