305 lines
7.7 KiB
Dart
305 lines
7.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class SharedPreferencesHelper {
|
|
static const VIP = 'vip';
|
|
static const USERID = 'userId';
|
|
static const LIKEMECOUNT = 'likeMeCount';
|
|
static const RECENTVISITCOUNT = 'recentVisitCount';
|
|
static const PHOTO = 'photo';
|
|
static const AUTHORIZATION = 'Authorization';
|
|
|
|
static const AVATAR = 'avatar';
|
|
static const NAME = 'name';
|
|
|
|
static const LOGINPHONE = 'loginPhone';
|
|
|
|
static const LOGINEmail = 'loginEmail';
|
|
|
|
static const PWD = 'pwd';
|
|
|
|
static const EmailPWD = 'EmailPWD';
|
|
|
|
static const AGREEMENT = 'agreement';
|
|
|
|
static const String firstLogin = 'first';
|
|
|
|
static const msgTip = 'msgTip';
|
|
|
|
static const FirstMatch = 'FirstMatch';
|
|
|
|
static const FirstAutoMatch = 'FirstAutoMatch';
|
|
|
|
static const FirstTashTip = 'FirstTashTip';
|
|
|
|
static const FirstUserHomeTip = 'FirstUserHomeTip';
|
|
|
|
static const SettingStatus = 'SettingStatus';
|
|
|
|
static const FirstPeopleSendCallOut = 'FirstPeopleSendCallOut';
|
|
|
|
|
|
static const UPDATE = 'update';
|
|
|
|
static const UPDATEONE = 'UPDATEONE';
|
|
|
|
static const fraudPreventionTip = 'fraudPreventionTip';
|
|
|
|
static const nearTip = 'nearTip';
|
|
|
|
static const serveTip = 'serveTip';
|
|
|
|
|
|
static const nearOpTip = 'nearOpTip';
|
|
|
|
static const circleCallOpTip = 'circleCallOpTip';
|
|
|
|
static const circleLikeOpTip = 'circleLikeOpTip';
|
|
|
|
static const calloutOpTip = 'calloutOpTip';
|
|
|
|
static const msgOpTip = 'msgOpTip';
|
|
|
|
static const mineOpTip = 'mineOpTip';
|
|
|
|
static const vipDayTip = 'vipDayTip';
|
|
|
|
static const FirstContact = 'FirstContact';
|
|
|
|
|
|
|
|
static SharedPreferencesHelper? _instance;
|
|
static SharedPreferences? _preferences;
|
|
|
|
SharedPreferencesHelper._();
|
|
|
|
static Future<SharedPreferencesHelper> getInstance() async {
|
|
if (_instance == null) {
|
|
_instance = SharedPreferencesHelper._();
|
|
await _instance!._initPreferences();
|
|
}
|
|
return _instance!;
|
|
}
|
|
|
|
Future<void> _initPreferences() async {
|
|
_preferences = await SharedPreferences.getInstance();
|
|
}
|
|
|
|
SharedPreferences? get preferences {
|
|
return _preferences;
|
|
}
|
|
|
|
Future<bool> isShowUpdate() async {
|
|
String time = await preferences!.getString(UPDATE) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(UPDATE, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(UPDATE, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Future<bool> isShowOneUpdate(String version) async {
|
|
String lastVersion = await preferences!.getString(UPDATEONE) ?? '';
|
|
if (lastVersion.isNotEmpty) {
|
|
bool isShow = lastVersion != version;
|
|
if (isShow) {
|
|
preferences!.setString(UPDATEONE, version);
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(UPDATEONE, version);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Future<bool> isShowNearLocation() async {
|
|
String time = await preferences!.getString(nearTip) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(nearTip, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(nearTip, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
setString(String key, String value) async {
|
|
final prefs = preferences;
|
|
|
|
prefs?.setString(key, value) ?? "";
|
|
}
|
|
|
|
setInt(String key, int value) async {
|
|
final prefs = preferences;
|
|
prefs?.setInt(key, value) ?? 0;
|
|
}
|
|
setBool(String key, bool value) async {
|
|
final prefs = preferences;
|
|
prefs?.setBool(key, value) ?? 0;
|
|
}
|
|
|
|
int getInt(String key) {
|
|
final prefs = preferences;
|
|
return prefs?.getInt(key) ?? 0;
|
|
}
|
|
|
|
String getString(String key) {
|
|
final prefs = preferences;
|
|
return prefs?.getString(key) ?? '';
|
|
}
|
|
|
|
String getMyUserId() {
|
|
return preferences?.getInt(SharedPreferencesHelper.USERID).toString() ?? '';
|
|
}
|
|
|
|
setStringList(List<String> value) {
|
|
final prefs = preferences;
|
|
return prefs?.setStringList(msgTip,value);
|
|
}
|
|
|
|
List<String> getStringList() {
|
|
final prefs = preferences;
|
|
return prefs?.getStringList(msgTip) ?? [];
|
|
}
|
|
|
|
|
|
Future<bool> isShowMatch() async {
|
|
String time = preferences!.getString(FirstMatch) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(FirstMatch, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(FirstMatch, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
Future<bool> isFirstAutoMatch() async {
|
|
String time = preferences!.getString(FirstAutoMatch) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(FirstAutoMatch, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(FirstAutoMatch, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
Future<bool> isFirstTashTip() async {
|
|
String time = preferences!.getString(FirstTashTip) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(FirstTashTip, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(FirstTashTip, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Future<bool> isFirstUserHomeTip() async {
|
|
String time = preferences!.getString(FirstUserHomeTip) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(FirstUserHomeTip, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(FirstUserHomeTip, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
Future<bool> isFirstPeopleSendCallOut() async {
|
|
String time = preferences!.getString(FirstPeopleSendCallOut) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(FirstPeopleSendCallOut, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(FirstPeopleSendCallOut, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Future<bool> isShowContact() async {
|
|
String time = preferences!.getString(FirstContact) ?? '';
|
|
if (time.isNotEmpty) {
|
|
DateTime dateTime = DateTime.parse(time);
|
|
bool isShow = !isSameDay(dateTime,DateTime.now());
|
|
if (isShow) {
|
|
preferences!.setString(FirstContact, DateTime.now().toString());
|
|
}
|
|
return isShow;
|
|
} else {
|
|
preferences!.setString(FirstContact, DateTime.now().toString());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
setFirstPeopleSendCallOut() {
|
|
preferences!.setString(FirstPeopleSendCallOut, DateTime.now().toString());
|
|
}
|
|
|
|
setSettingStatus(bool status) {
|
|
preferences!.setBool(SettingStatus, status);
|
|
}
|
|
|
|
|
|
|
|
bool isSameDay(DateTime time1, DateTime time2) {
|
|
return time1.year == time2.year &&
|
|
time1.month == time2.month &&
|
|
time1.day == time2.day;
|
|
}
|
|
|
|
bool? getBool(String key) {
|
|
final prefs = preferences;
|
|
return prefs?.getBool(key);
|
|
}
|
|
|
|
bool containsKey(String key) {
|
|
bool? status = preferences?.containsKey(key);
|
|
print(status);
|
|
return preferences?.containsKey(key) ?? false;
|
|
}
|
|
|
|
void clear() {
|
|
final prefs = preferences;
|
|
prefs?.clear();
|
|
}
|
|
|
|
}
|