jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.44k stars 1.63k forks source link

View update as list update in controller #527

Closed ziasultan2 closed 4 years ago

ziasultan2 commented 4 years ago

Fill in the template. Issues that do not respect the model will be closed.

Describe the bug How can I update specific value inside view

Expected behavior update data in listview

Minimal reproduce code Provide a minimum reproduction code for the problem

// List of Foods 
final cart = List<Foods>().obs;

  increase(index) {
  // Here I'm updating the value in list how can I update this in view. 
 // Here index is the index position of food in cart list
    cart.value[index].quantity++;
    update();
  }

I tried cart.update() but it's not showing any relevant method to update list

jonataslaw commented 4 years ago

I am closing this issue because it does not contain a case of reproduction, and because it is an inappropriate use of the library. If you think this is really a bug, open another issue with a valid reproduction case, but first, read the documentation above, and check if really what you are facing is a bug, before opening an issue. Community channels are the fastest place for you to ask questions like this.

Nipodemos commented 4 years ago

just to complete the issue, since have a observable list usually is not the best, you should instead have a normal list of observable values:

//before:
final cart = List<Foods>().obs;

//after
final cart = List<Rx<Foods>>();

that way you have a list with multiple observable food classes

and to update them:

cart[index].update( (food) { // this parameter is the class itself that you want to update
food.quantity++;
});

coincidence or not, the documentation about this were added today! https://github.com/jonataslaw/getx/blob/master/docs/en_US/state_management.md#note-about-lists

ziasultan2 commented 4 years ago

Thank you dear for this solution.

On Sat, Aug 29, 2020 at 11:53 PM Nipodemos notifications@github.com wrote:

just to complete the issue, since have a observable list usually is not the best, you should instead have a normal list of observable values:

//before:final cart = List().obs; //afterfinal cart = List<Rx>();

that way you have a list with multiple observable food classes

and to update them:

cart[index].update( (food) { // this parameter is the class itself that you want to update food.quantity++; });

coincidence or not, the documentation about this were added today!

https://github.com/jonataslaw/getx/blob/master/docs/en_US/state_management.md#note-about-lists

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jonataslaw/getx/issues/527#issuecomment-683322444, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACQSUSCARASZZLZXAC5XP53SDE6CTANCNFSM4QPBBRWQ .