I am making an application using Flutter that handles its login with Firebase Authentication. The authentication works fine, but I am curious as to the best practice in storing the User object.
Currently, signing up/logging in converts the database user's fields into a User object. Because of the necessity of this information app-wide, I would like to make this information accessible "globally". Of course, before the user ever modifies the database or another vital function I will ensure they are truly authenticated.
I am currently handling this by having a global library with a User singleton, but I have heard that globals, and therefor singletons, are generally a bad practice. Eventually I would like it so that the user stays authenticated even after closing the application, so I will likely end up using SharedPreferences.
Should I just use SharedPreferences for this? Should I keep using my global library and also integrate SharedPreferences? Should I somehow use Provider?
Basically two questions:
- What is generally the best practice in Flutter/Dart for storing the user object in the current session?
- What is generally the best practice in Flutter/Dart for storing the user object for future sessions?