Because SharedPreferences, by its very nature, is singleton (i.e. There’s only one ‘preferences’ per app) indeed the singleton approach is being used in this library. It’s just all in the delivery. True, the use of a singleton factory class would be just as effective. Just not as pretty.

Any developer experienced with this library can simply import it to their Dart file, prefix the ol’ ‘Prefs’ in front of whatever library function they wish to use in their particular circumstance, and they’re off and running!

Being all static functions, they be can called anytime; anywhere without having to call a factory class first and assign to a variable, etc. Done! That developer then gets on with their life. Another developer, possibly just as familiar with the library, can later come across the code and can already recognize what’s going on…at least in that regard. Self-contained. Clean.

Greg

Freelance Developer

Freelance Developer