-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChangeNotifier LifeCycle #799
Comments
Hello again! Could you expand on what those callbacks are supposed to do? I'm also not sure what the issue with Timer as you mentioned is. |
Yes, @rrousselGit actually I just want to add replica of initState() in our ChangeNotifier, this callback is just like the one already added in ChangeNotifier i.e. dispose(). So, what i want to mention is that ChangeNotifier class has dispose() method in it, I want to add onInit() and onReady() callback inside it which will be really helpful for all of us, because most of the time we need to execute a piece of code in initState() and just for initState() callback we need to convert our StatelessWidget into Stateful. Stateful widget also have alot of boilerplate code as compared to Stateless, so if we create onInit() and onReady() callback in ChangeNotifier, then one can directly execute code inside our ChangeNotifier's onInit callback. Let me know if its still confusing😊 |
after implementations there will be three callbacks in ChangeNotifier class
|
Could you not use the ChangeNotifier's constructor? class Foo with ChangeNotifier {
Foo() {
// Perform initState-like logic
}
} Also |
what you wrote just like getx ? my advice is stay away from changeNotifier. you only use it if others way didnt work |
It feels very useful |
Hi, I'm writing to let you know that I have an idea to create a lifecycle for ChangeNotifier
right now ChangeNotifier have only a single method called dispose(), whenever we need to execute a piece of code on model destruction we can put that code inside dispose() callback. but there are certain problems we face in real world apps that we do not have any callback of model initialization.
Real World Scenarios:
lets we have a screen [consider a SplashScreen], and we want that screen to show for sometime let say Timer(seconds: 5), now what we could write in our code? for now we have stateful widgets and we can utilize initState() callback, but there are some points in initState()
Solution
For these types of scenarios, I want to create some separate callbacks in ChangeNotifier like, onInit() and onReady(), this will be triggered just after ChangeNotifier is injected into the memory and we can configure our things inside these callbacks.
Code Snippets
The text was updated successfully, but these errors were encountered: