Skip to content

Instantly share code, notes, and snippets.

@littleironical
Created December 4, 2020 16:47
Show Gist options
  • Save littleironical/8899576a76befd4655fa453952cce4c5 to your computer and use it in GitHub Desktop.
Save littleironical/8899576a76befd4655fa453952cce4c5 to your computer and use it in GitHub Desktop.
// SAVING DATA
saveString(key, value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString(key, value);
}
saveDouble(key, value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setDouble(key, value);
}
saveInt(key, value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt(key, value);
}
saveBool(key, value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool(key, value);
}
// RETRIEVING DATA
retrieveString(key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
//Return String
String stringValue = prefs.getString(key);
return stringValue;
}
retrieveDouble(key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
//Return double
double doubleValue = prefs.getDouble(key);
return doubleValue;
}
retrieveInt(key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
//Return int
int intValue = prefs.getInt(key);
return intValue;
}
retrieveBool(key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
//Return bool
bool boolValue = prefs.getBool(key);
return boolValue;
}
// DELETING DATA
removeValues() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
//Remove String
prefs.remove("stringValue");
//Remove bool
prefs.remove("boolValue");
//Remove int
prefs.remove("intValue");
//Remove double
prefs.remove("doubleValue");
}
// CHECKING DATA
bool CheckValue = prefs.containsKey('value');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment