skip to Main Content

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


  1. Short answer: You can’t.

    Long answer: You can change where the setState is called, create a separate StatefulWidget 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 use Provider, Riverpod or BLoC (which i personally recommend). If you want something a litte bit easier you can start learning how to use InheritedWidget starting in the documentation right here.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search