Created
September 8, 2019 03:42
-
-
Save SOY4RIAS/09b67baa2e9efb21af32b14414a12ffb to your computer and use it in GitHub Desktop.
Flutter SharedPreferences template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:shared_preferences/shared_preferences.dart'; | |
/** | |
* This Class was developed by Singleton pattern | |
* | |
* The recommended use is: | |
* * init on main function before runApp | |
*/ | |
class UserPreferences { | |
static final UserPreferences _instance = UserPreferences._(); | |
factory UserPreferences() => _instance; | |
UserPreferences._(); | |
SharedPreferences _prefs; | |
initPrefs() async { | |
_prefs = await SharedPreferences.getInstance(); | |
} | |
/* | |
* This Section is to handle the last page visit by the user | |
*/ | |
//get lastPage { | |
// return _prefs.getString('lastPage') ;// ?? HomePage.routeName; | |
//} | |
//set lastPage(value) { | |
// _prefs.setString('lastPage', value); | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment