2024-09-06 06:30:31 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class SessionManager {
|
|
|
|
static final SessionManager _instance = SessionManager._();
|
2024-10-09 08:53:25 +00:00
|
|
|
static const String _loggedInKey = 'isloggedin';
|
2024-09-06 06:30:31 +00:00
|
|
|
|
|
|
|
factory SessionManager() {
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
SessionManager._();
|
|
|
|
|
|
|
|
Future<void> setLoggedIn(bool value) async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.setBool(_loggedInKey, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> isLoggedIn() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
return prefs.getBool(_loggedInKey) ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> clearSession() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.clear();
|
|
|
|
}
|
2024-10-07 12:45:45 +00:00
|
|
|
|
|
|
|
Future<void> logoutSession(bool value) async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
2024-10-09 08:53:25 +00:00
|
|
|
//secretkey
|
|
|
|
|
2024-10-07 12:45:45 +00:00
|
|
|
await prefs.setBool("isloggedin", value);
|
2024-10-09 08:53:25 +00:00
|
|
|
await prefs.setBool("isloggedout", true);
|
|
|
|
await prefs.setBool(_loggedInKey, value);
|
2024-10-07 12:45:45 +00:00
|
|
|
}
|
2024-09-06 06:30:31 +00:00
|
|
|
}
|