Reputation: 3517
From what I understand about the flutter package, Provider
, is that it's a way to share objects between widgets. I know another way of doing this is to create a class, say AppGlobal
, and define various static
variables that the whole app could use. It's suggested that Provider
is a better way of doing that, but I don't understand why that is.
Upvotes: 22
Views: 7278
Reputation: 2192
An answer to the question should take different aspects into account:
lazy: false
Hope this answers the question in more depth.
Upvotes: 18
Reputation: 49
A quick search through the web and it seems like a global instance of a variable is not the best idea since it is not testable, and it makes the code very coupled with the AppGlobal class.
Here is a link that describes what I am talking about and it does a great job with examples.
Global Access vs Scoped Access with Provider
Upvotes: 4