Samuel Mora Rodriguez
Samuel Mora Rodriguez

Reputation: 11

how to exclude a widget from setState?

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

Upvotes: 0

Views: 933

Answers (2)

Sayyid J
Sayyid J

Reputation: 1573

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

Upvotes: 0

Kentukyyo
Kentukyyo

Reputation: 426

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.

Upvotes: 2

Related Questions