This commit is contained in:
Mohammed Al-Samarraie
2026-01-13 12:43:43 +03:00
parent 4df24f5d8d
commit ac8a769ff0
23 changed files with 945 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
# Data sources directory
# Create your remote data sources here following this pattern:
#
# abstract class YourRemoteDataSource {
# Future<YourDto> yourMethod(YourRequest request);
# }
#
# class YourRemoteDataSourceImpl implements YourRemoteDataSource {
# final ApiClient apiClient;
#
# YourRemoteDataSourceImpl({required this.apiClient});
#
# @override
# Future<YourDto> yourMethod(YourRequest request) async {
# try {
# final response = await apiClient.post(
# '/your-endpoint',
# data: request.toJson(),
# );
# // Handle response and return DTO
# } on DioException catch (e) {
# // Handle errors
# }
# }
# }

View 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);
}
}