Skip to content

Instantly share code, notes, and snippets.

@ShanmugavelGK
Last active June 20, 2018 09:47
Show Gist options
  • Save ShanmugavelGK/15b5fe8be03062e99da12aead97eb0d8 to your computer and use it in GitHub Desktop.
Save ShanmugavelGK/15b5fe8be03062e99da12aead97eb0d8 to your computer and use it in GitHub Desktop.
SharedPreferences common class, first add dependencies " shared_preferences: "^0.4.2" "
import 'package:shared_preferences/shared_preferences.dart';
class SharedPreference {
SharedPreferences prefs;
init() async {
prefs = await SharedPreferences.getInstance();
}
void setStringValue(String key, String value) {
prefs.setString(key, value);
}
String getStringValue(String key) {
return prefs.getString(key);
}
void setIntValue(String key, int value) {
prefs.setInt(key, value);
}
int getIntValue(String key) {
return prefs.getInt(key);
}
void setBoolValue(String key, bool value) {
prefs.setBool(key, value);
}
bool getBoolValue(String key) {
return prefs.getBool(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment