From f415aa16762d9ebc7eaa0118ed5caab162e5c4e8 Mon Sep 17 00:00:00 2001 From: raf-dev1 Date: Wed, 11 Jun 2025 12:57:00 +0300 Subject: [PATCH] Delete unused File --- lib/core/network/request.dart | 121 ---------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 lib/core/network/request.dart diff --git a/lib/core/network/request.dart b/lib/core/network/request.dart deleted file mode 100644 index c242b8a6..00000000 --- a/lib/core/network/request.dart +++ /dev/null @@ -1,121 +0,0 @@ -import 'dart:convert'; - -import 'package:dio/dio.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; - -import '../../pages/auth/model/token.dart'; -import 'custom_exceptions.dart'; -import 'dio.dart'; -import 'enums.dart'; - -class Request { - String endPoint; - bool? autherized; - bool? isFormData; - RequestType? method; - Map? headers; - final Map? queryParams; - Map? body; - Duration? receiveTimeout; - Request( - this.endPoint, { - this.autherized, - this.isFormData, - this.method, - this.headers, - this.queryParams, - this.body, - this.receiveTimeout, - }) { - headers = { - 'content_Type': 'application/json', - 'Accept': 'application/json', - }; - } - Future> sendRequest() async { - Response? response; - if (autherized != null && autherized!) { - final storage = const FlutterSecureStorage(); - final token = await storage.read(key: Token.loginAccessTokenKey); - if (token != null) { - headers!["authorization"] = "Bearer $token"; - } - } - try { - response = await DioInstance().dio.request( - endPoint, - queryParameters: queryParams, - data: isFormData != null && isFormData == true - ? FormData.fromMap(body!) - : body, - options: Options( - method: method!.name.toUpperCase(), - headers: headers, - contentType: 'application/json', - receiveTimeout: receiveTimeout, - ), - ); - if (response.statusCode! >= 200 && response.statusCode! < 300) { - return response.data; - } - } on DioException catch (error) { - if (error.type == DioExceptionType.badResponse) { - throw badRequestException[error.response!.data["error"]] ?? - const GenericException( - type: ExceptionType.other, - ); - } - if (error.type == DioExceptionType.connectionError || - error.type == DioExceptionType.connectionTimeout || - error.type == DioExceptionType.receiveTimeout || - error.type == DioExceptionType.sendTimeout || - error.type == DioExceptionType.unknown) { - throw const GenericException( - type: ExceptionType.connectionError, - errorMessage: 'no_internet_connection', - ); - } - } - return {}; - } - - Map toJson() => { - 'endPoint': endPoint, - 'method': method!.name.toUpperCase(), - 'body': json.encode(body), - 'headers': headers, - 'queryParams': queryParams, - 'autherized': autherized, - 'isFormData': isFormData, - }; - @override - String toString() { - return jsonEncode(toJson()); - } - - List get props => [ - endPoint, - autherized, - isFormData, - method, - headers, - queryParams, - body, - receiveTimeout, - ]; -} - -Map badRequestException = { - ExceptionMessage.INVALID_CREDENTIALS.name: const GenericException( - type: ExceptionType.invalidCredentials, - errorMessage: "Invalid credentials ...", - ), - "The password field must be at least 8 characters.": const GenericException( - type: ExceptionType.invalidValidation, - errorMessage: 'password must be 8 or more characters', - ), - ExceptionMessage.NOT_AUTHENTICATED.name: const GenericException( - type: ExceptionType.notAuthenticated, - errorMessage: "not authenticated", - ), -};