Jonathan John
Jonathan John

Reputation: 13

How to setstate in one statefulwidget when a button is clicked in another statefulwidget?

So I have one parent statefulwidget that contains a TabBarView. The child to this tabbarview are two different child statefulwidgets.

What I want to achieve is that if I press a button in one of those child statefulwidgets, it should animate the tabcontroller and also set state in the parent statefulwidget.

How to do that? Thanks

Upvotes: 0

Views: 538

Answers (3)

MoAshour
MoAshour

Reputation: 179

have a look at the below link Let the parent widget manages the widget’s state

Upvotes: 0

Ali Alizadeh
Ali Alizadeh

Reputation: 705

You need to create a function in the parent widget which changes the tab and sets the state, and then pass that as a parameter to the children widgets and call it when needed.

Upvotes: 1

Related Questions