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

How to observe changes in a list of objects #358

Closed Kypsis closed 4 years ago

Kypsis commented 4 years ago

How do I detect changes in a list of objects with Get? For example I have:

class Video {
  VideoPlayerController controller;
  final String url;

  Video(this.url);
}

class VideosController extends GetxController {
  static VideosController get to => Get.find();

var videosList = [
    Video("https://whatever.co/tmpfiles/1.mp4"),
    Video("https://whatever.co/tmpfiles/2.mp4"),
    Video("https://whatever.co/tmpfiles/3.mp4"),
  ].obs;
}

How would I detect with Get if the videoController property has changed (for instance async function has attached a Video Player controller to it) on a specific object, any object or the list as whole to have Obx() rerender it's widgets.

It doesn't seem that obs detects if any of the objects videoController value is not null anymore.

jonataslaw commented 4 years ago

Hi, please try to post questions on the appropriate channels, github is dedicated to bugs and feature requests. But to answer your question quickly, this is not the role of GetX. You can simply create a reactive bool, and change it to true when everything is ready, it is the best way, but observing changes in a VideoPlayerController has nothing to do with the project, nor with the state management itself, but as mentioned above, you can mediate this and assign something to the state manager, changing observable variables, like enums or booleans to do what you want. Closing it.