11111
This commit is contained in:
29
lib/data/datasources/user_local_data_source.dart
Normal file
29
lib/data/datasources/user_local_data_source.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
abstract class UserLocalDataSource {
|
||||
Future<void> cacheUserToken(String token);
|
||||
Future<String?> getCachedUserToken();
|
||||
Future<void> clearCache();
|
||||
}
|
||||
|
||||
class UserLocalDataSourceImpl implements UserLocalDataSource {
|
||||
final SharedPreferences sharedPreferences;
|
||||
static const String _tokenKey = 'user_token';
|
||||
|
||||
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> clearCache() async {
|
||||
await sharedPreferences.remove(_tokenKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user