Files
finger_print_app/lib/data/datasources/user_local_data_source.dart
2026-02-17 16:51:13 +03:00

58 lines
1.6 KiB
Dart

import 'package:shared_preferences/shared_preferences.dart';
abstract class UserLocalDataSource {
Future<void> cacheUserToken(String token);
Future<String?> getCachedUserToken();
Future<void> clearCache();
Future<void> cacheEmployeeId(String id);
Future<String?> getCachedEmployeeId();
Future<void> cacheFullName(String name);
Future<String?> getCachedFullName();
}
class UserLocalDataSourceImpl implements UserLocalDataSource {
final SharedPreferences sharedPreferences;
static const String _tokenKey = 'user_token';
static const String _employeeIdKey = 'employee_id';
static const String _fullNameKey = 'full_name';
UserLocalDataSourceImpl({required this.sharedPreferences});
@override
Future<void> cacheUserToken(String token) async {
await sharedPreferences.setString(_tokenKey, token);
}
@override
Future<String?> getCachedUserToken() async {
return sharedPreferences.getString(_tokenKey);
}
@override
Future<void> cacheFullName(String name) async {
await sharedPreferences.setString(_fullNameKey, name);
}
@override
Future<String?> getCachedFullName() async {
return sharedPreferences.getString(_fullNameKey);
}
@override
Future<void> cacheEmployeeId(String id) async {
await sharedPreferences.setString(_employeeIdKey, id);
}
@override
Future<String?> getCachedEmployeeId() async {
return sharedPreferences.getString(_employeeIdKey);
}
@override
Future<void> clearCache() async {
await sharedPreferences.remove(_tokenKey);
await sharedPreferences.remove(_employeeIdKey);
await sharedPreferences.remove(_fullNameKey);
}
}