I am designing an application that uses setState to refresh a screen with all its widgets, however I would like to know if there is a way to exclude a particular widget (conainer) and all its children, as if I were treating it as a new page.
I tried to use Navigator.push (context, MaterialPageRoute), but it didn’t work, I would like to treat the widget as a separate page. I appreciate any help
2
Answers
Short answer: You can’t.
Long answer: You can change where the
setState
is called, create a separateStatefulWidget
that contains only the ones that need to be rebuilded. However in most of the cases this is not possible because of the order you need to show your widgets or many other factors. That’s when State Managements tools come in handy. You should try to learn how to useProvider
,Riverpod
orBLoC
(which i personally recommend). If you want something a litte bit easier you can start learning how to useInheritedWidget
starting in the documentation right here.use
const
if possible. if not,use StatefulBuilder , if you call setState inside this widget, the outside widget is not touched. Maybe it will suit what you need