37 lines
972 B
Dart
37 lines
972 B
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class SessionManager {
|
|
static final SessionManager _instance = SessionManager._();
|
|
static const String _loggedInKey = 'isloggedin';
|
|
|
|
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();
|
|
}
|
|
|
|
Future<void> logoutSession(bool value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
//secretkey
|
|
|
|
await prefs.setBool("isloggedin", value);
|
|
await prefs.setBool("isloggedout", true);
|
|
await prefs.setBool(_loggedInKey, value);
|
|
}
|
|
}
|