Flutter, State Management with Provider Package. A Data guy view.
Just discovered Flutter and I must say that it's becoming pleasant to develop for Android, moreover with one code base you can deliver apps for Android, iPhone, Web, and OSs. There's a great amount of excellent documentation on Flutter so I won't treat any of the technical details on how to implement State Management in Flutter with the Provider package. My intent here is to share some considerations of someone who just started to learn Flutter and has some background. I'm just at the beginning so there is a lot I need to learn here and I might have misunderstood many things, nevertheless since I can't sleep this night I want to put out this ramblings, I'm very glad if anyone can correct & teach me.
When you decide to use the Provider pattern for State Management you will create classes that hold data which will be shared across the whole application. When you start an app using the Provider pattern you will ask the framework to instantiate an object of one class present in the data holding module (btw you can use MultiProvider to use more provider classes), that class instance will be available in the whole Widget tree and will be accessible via the Context(recent versions also made the syntax leaner).
To cut the story short I see the class, or better the instance, holding the data similar to a backend database because you have only one centralized source of truth which can be accessible by the whole app, wherever you change an instance property that will be immediately visible to any other part of the application. Functions of the class can be seen as Stored Procedures, which can retrieve but also change data. This view on the Provider pattern made me easy to digest it right away and it will probably be one of my favourite State Management patterns as long as I won't see any particular limitations. I still have to understand if you can instantiate multiple objects from the class or even create a List of instances of the class to emulate a database table, right now my solution is to create a List inside the class of items of interest. To implement persistence you need something like sqlite or SharedPreferences (for small data).
Two words on the general approach of Widget tree update and building in Flutter; being able to access and use the properties of the class instance in the Widgets makes interfaces extremely precise as you can't forget to update info in any part of the UI, that's done automatically by the framework (provided you call notifyListeners() for Provider package) by rebuilding the part of the Widget tree interested by the change(subscribed as consumer).
Good Night.