Wrap ChangeNotifier with an AsyncNotifier #3810
Unanswered
gazialankus
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I just tested it and it works just fine 😊. I guess this is how you wrap a ChangeNotifier in the latest Riverpod. Feels much better than providing a ChangeNotifier instance and listening to it myself. The listening bit is encapsulated within the AsyncNotifier and I get to use it the way I expect. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am given a ChangeNotifier and I would love to use it as a first class citizen in my Riverpod app that uses generator and the general approach in the latest docs.
I thought I could wrap it with an AsyncNotifier in which every notifyListeners call of the ChangeNotifier would trigger a state change. AsyncNotifier since its initialization is also async.
The ChangeNotifier in question is SessionManager from Serverpod btw. Here's what I wrote but didn't test, do you think this is a good approach in wrapping a ChangeNotifier?
I did the removing listener from the existing one part just in case I
ref.invalidate
it at some point.The part that I'm not sure is setting the state using the exact same instance once again, not sure if it will cause a refresh or will be ignored.
Please let me know what you think. It would be nice to hear if you have a better way of wrapping a ChangeNotifier.
Beta Was this translation helpful? Give feedback.
All reactions