11111
This commit is contained in:
25
lib/data/datasources/.gitkeep
Normal file
25
lib/data/datasources/.gitkeep
Normal 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
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
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);
|
||||
}
|
||||
}
|
||||
24
lib/data/dto/.gitkeep
Normal file
24
lib/data/dto/.gitkeep
Normal file
@@ -0,0 +1,24 @@
|
||||
# DTO (Data Transfer Objects) directory
|
||||
# Create your DTOs here for API request/response mapping
|
||||
# Example:
|
||||
#
|
||||
# class LoginDto {
|
||||
# final String phoneNumber;
|
||||
# final String password;
|
||||
#
|
||||
# LoginDto({required this.phoneNumber, required this.password});
|
||||
#
|
||||
# Map<String, dynamic> toJson() {
|
||||
# return {
|
||||
# 'phoneNumber': phoneNumber,
|
||||
# 'password': password,
|
||||
# };
|
||||
# }
|
||||
#
|
||||
# factory LoginDto.fromJson(Map<String, dynamic> json) {
|
||||
# return LoginDto(
|
||||
# phoneNumber: json['phoneNumber'],
|
||||
# password: json['password'],
|
||||
# );
|
||||
# }
|
||||
# }
|
||||
27
lib/data/repositories/.gitkeep
Normal file
27
lib/data/repositories/.gitkeep
Normal file
@@ -0,0 +1,27 @@
|
||||
# Repository implementations directory
|
||||
# Create your repository implementations here
|
||||
# Example:
|
||||
#
|
||||
# class AuthRepositoryImpl implements AuthRepository {
|
||||
# final AuthRemoteDataSource remoteDataSource;
|
||||
# final UserLocalDataSource localDataSource;
|
||||
#
|
||||
# AuthRepositoryImpl({
|
||||
# required this.remoteDataSource,
|
||||
# required this.localDataSource,
|
||||
# });
|
||||
#
|
||||
# @override
|
||||
# Future<Either<Failure, LoginResponseModel>> login(LoginRequest request) async {
|
||||
# try {
|
||||
# final dto = LoginDto(...);
|
||||
# final responseDto = await remoteDataSource.login(dto);
|
||||
# final responseModel = _convertDtoToModel(responseDto);
|
||||
# return Right(responseModel);
|
||||
# } on ServerException catch (e) {
|
||||
# return Left(ServerFailure(e.message));
|
||||
# } on NetworkException catch (e) {
|
||||
# return Left(NetworkFailure(e.message));
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
Reference in New Issue
Block a user