Manage state for nested classes using Flutter Provider

Viewed 313

Currently am working on Sport Event Scoring app. The structure of the app goes something like this:

enter image description here

Right now I am trying to include state management using provider package.

Scoring occurs at the very bottom of the Widget tree using a counter and each Widget initializes respectively named model based on a user input on the go - creating Event, adding divisions and players each happens in a dialog.

I know I need to create a provider for list of Events, however, I am not sure how to go about structuring rest of the state management. So far I tried turning each model into a Provider by mixin in the ChangeNotifier and moving all the methods which change the data inside where the state would be managed as well with notifyListeners(). However after a lot of struggling and searching I found that it's not the best approach to manage the state inside models.

What approach would be ideal? Should I manage the state through the Event List provider, or should I go with creating a provider for each model in a separate file? If so, how?

1 Answers

I am not too sure about the full scope of your project nor how far you are into it but I would highly suggest checking out the BLOC library as an alternative state management solution to simply manage the state in your case.

The learning curve is fairly low with many tutorials on how exactly to use the library alongside the fact that BLOC is much less reliant on listeners from an external persons view using the library from my experiences if that is what you are struggling with.

Here is a link to the BLOC Library

If you are still persistent to use Provider, I would suggest you create a provider for each model in a separate file for multiple reasons such as separation of concerns and ease of management of state and clarity of each different model.

Related