0

I'm still learning Flutter and trying to understand best practices.

One of them seems to be that global variables are bad, and recommends using something like Provider instead.

In my case, I have a bunch of settings that are read from the back end when the app first starts. The variables in globals.dart are assigned values on startup, and then don't change after being assigned.

int maxLoginAttempts...
String welcomeMessage...
...

My confusion comes from the fact that most people who've asked this question (that I have found, sorry if I missed a post somewhere) are creating variables whose value may change as the application is used. I can understand something like Provider and ChangeNotifier would work well for that.

But in my case the values are assigned once - and don't change thereafter - they're only read.

So are globals still bad in my case?

1 Answers1

0

In your case no provider/state management is needed if you are just assigning some value to global variable and and its value change does not require widget rebuild.

IonicFireBaseApp
  • 925
  • 3
  • 10