Providers are completely new things for anyone switching to Flutter from Native mobile apps development. There are lots and lots of articles written on it. In this article I have shared my knowledge on one of the type of Provider, that is “ProxyProvider”. This article is requires your understanding of Dart, State Management in Flutter, “Provider” Package, ChangeNotifier and so on. So this is definitely not for beginners.
- •Class Name: “HOUSE” => Is ChangeNotifier
- •Class Name: “BALCONY” => Is not ChangeNotifier
- “HOUSE” is dependency injected to “BALCONY”.
- ProxyProvider is used to inject this dependency.
- Now there are two ways we can use ProxyProvider.
- ProxyProvider has one main method to be careful of. It is “Update” method.
- So main magic happens in this “Update” method.
- “Update” method determines how to react to the change in injected dependency.
a) Using “Update” Method First way:
b) Using “Update” Method Second way:
c) Invoked “Update” Method inside the Proxy class (“Balcony” here).
I hope above code will be useful and help you understand “ProxyProvider”.