Skip to content

Instantly share code, notes, and snippets.

@SOY4RIAS
Created September 8, 2019 03:42
Show Gist options
  • Save SOY4RIAS/09b67baa2e9efb21af32b14414a12ffb to your computer and use it in GitHub Desktop.
Save SOY4RIAS/09b67baa2e9efb21af32b14414a12ffb to your computer and use it in GitHub Desktop.
Flutter SharedPreferences template
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