Skip to content

Instantly share code, notes, and snippets.

@theindianappguy
Created January 12, 2021 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theindianappguy/4e4eb61acd1285d44eb89aeff482c445 to your computer and use it in GitHub Desktop.
Save theindianappguy/4e4eb61acd1285d44eb89aeff482c445 to your computer and use it in GitHub Desktop.
import 'package:shared_preferences/shared_preferences.dart';
class SharedPreferenceHelper {
static String userIdKey = "USERIDKEY";
static String userNameKey = "USERNAMEKEY";
static String displayNameKey = "USERDISPLAYNAME";
static String userEmailKey = "USEREMAILKEY";
static String userProfilePicKey = "USERPROFILEKEY";
//save data
Future<bool> saveUserName(String userName) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setString(userNameKey, userName);
}
Future<bool> saveUserEmail(String getUseremail) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setString(userEmailKey, getUseremail);
}
Future<bool> saveUserId(String getUserId) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setString(userIdKey, getUserId);
}
Future<bool> saveDisplayName(String getDisplayName) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setString(displayNameKey, getDisplayName);
}
Future<bool> saveUserProfileUrl(String getUserProfile) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setString(userProfilePicKey, getUserProfile);
}
//get data
Future<String> getUserName() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(userNameKey);
}
Future<String> getUserEmail() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(userEmailKey);
}
Future<String> getUserId() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(userIdKey);
}
Future<String> getDisplayName() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(displayNameKey);
}
Future<String> getUserProfileUrl() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(userProfilePicKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment