GetX Observable works with list but not custom class

Viewed 36

I am using GetX and Firebase Realtime Database. When I use this in my GetX controller, and Update a certain value (like the username), the Obx widget in my main screen is updated. Everything works smoothly.

Rx<List<FrediUser>> frediUser = Rx<List<FrediUser>>([]);
String get username => frediUser.value.first.username;

@override
void onInit() async {
    super.onInit();
    User? user = Get.find<AuthController>().user;
    String uid = user!.uid;
    frediUser.bindStream(DatabaseManager().frediUserStream(uid));
    ever(frediUser, everCalled);
}

But I only have one current user which I want to fetch, so making it a list is unnecesary. If I take the list off like so: Rx<FrediUser?> frediUser = Rx<FrediUser?>(null); it stops working. Of course I modify the subsequent lines to adjust for this. Or if I am using a custom class it doesn't notice the update. Note: The stream is called (checked with a print statement), but it is as if the update never gets to the controller or the UI.

It seems as if the value is nullable, the ever function is not called.

Related question: here

1 Answers

Change it to the following:

Rxn<FrediUser> frediUser = Rxn<FrediUser>();
String get username => frediUser.value.first.username;
Related