I have this class and use "reactive" state management e.g.
"".obs
Now I plan to initialize my state from local storage (get_storage) onInit()
problem:
where do I persist my data? As soon as some state changes, I want to persist it as well.
I tried using a listener but it never fires.
Currently I have this:
class CosController extends GetxController {
final box = GetStorage();
RxString econtactnr = ''.obs;
@override
void onInit() {
super.onInit();
addListener(() { //NEVER fires
print('hellowwww listener');
});
econtactnr.value = box.read('econtactnr') ?? '';
}
What is a best practice to store state to disk in GetXControllers using reactive state management?
EDIT: I noticed that you can do:
econtactnr.listen((x) {
box.write('econtactnr', econtactnr.value);
});
question: is that ok? do I have to cancel that subscription as well?