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

Deepak Kr Gupta
  • 6,994
  • 2
  • 21
  • 34

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
  • 216,050
  • 72
  • 473
  • 395