1

I use the provider package to manage my application state. I have a few questions concerning how to manage the state in the application.

  • Is it a good practice to create a ChangeNotifier class for each screen in my application to handle the back end for this page (which is provided to only this screen) ?

In an example like this: If i have a page that have multiple widgets and i need to rebuild a small part of the page like adding a new TextField on enabling a switch.

in the previous example

  • Should i use a provider to only rebuild the small part of the page or this part is mostly handled by only using changeState() ?

in case that the local-state of the page should be handled in the screen.

  • Where should i place the logic of the page, like http requests on button clicks and loading data for this page ?
Omar Alaa
  • 141
  • 2
  • 13

1 Answers1

0

If the state that you are updating is only needed within one widget with one or two down widgets down the tree, I would recommend using the built-in SetState. While both Provider and SetState would work for any form of state management, I tend to think of Provider as similar to React Context.

  • Provider is great for holding state at page levels or if you want to maintain the separation between widget builds and logic in different files.
  • SetState is great for local widgets with not a lot of nested widgets underneath.

Here is a great article that discusses the different state management solution approaches. At the end of the day, it's up to preference!

Eli017
  • 31
  • 7