0

I have two stateful states, ABCState and XYZState, I want to call setState() on ABCState from XYZState so that I can trigger a redraw of ABCState

class ABCState extends State<ABC> {

}

& 

Class XYZState extends State<XYZ> {
    // Call .setState() of ABCState
}

I tried to play around with keys, but somehow not able to do so. Appreciate your help

Daksh Gupta
  • 7,554
  • 2
  • 25
  • 36

1 Answers1

2

This is a bad idea. But if you want to do it, you can :

  • Use GlobalKey, which allows to get state/context/widget
  • Use BuildContext of the children of your desired stateful widget. Using context.ancestorStateOfType(const TypeMatcher<MyStatefulWidget>());
Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432