Let's say, I have a custom button widget and I want to set the state of it's parent using setState
. How exactly can I access the parent widget's state from my custom button? Is it even possibile?
You can create the field counter in the parent and pass it down to the child widget and update the child widget from the parent.
Using setState to rebuild widgets Flutter gives you access to setState() . In this case, we have to ensure setState() has the new values. When setState() is called, Flutter will know to get these new values and mark the widget that needs to be rebuilt.
How do you call a function in a child from parent in flutter? Create a Function type parameter inside your child widget. Pass the function goToPreviousItem as a parameter from the parent widget to child widget. Access your function using widget.
You can use callbacks functions to achieve this. You can refer here.
In the link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With