Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set State of parent Widget

Tags:

flutter

parent

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?

like image 833
Ian Rehwinkel Avatar asked Aug 29 '18 17:08

Ian Rehwinkel


People also ask

How do I change the state of my child from parent Flutter?

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.

How do I refresh a specific widget in Flutter?

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 the method of a parent widget from a child in Flutter?

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.


1 Answers

You can use callbacks functions to achieve this. You can refer here.

In the link

  • FeedPage is similar to CustomButton(ChildWiget)
  • RootPage is similar to ParentWiget
like image 113
Dinesh Balasubramanian Avatar answered Oct 24 '22 04:10

Dinesh Balasubramanian