formatted all files.

This commit is contained in:
Faris Armoush
2025-06-12 15:33:32 +03:00
parent 29959f567e
commit 04250ebc98
474 changed files with 5425 additions and 4338 deletions

View File

@ -1,10 +1,10 @@
import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:syncrow_web/pages/auth/model/token.dart';
import 'package:syncrow_web/services/api/network_exception.dart';
import 'dart:async';
import 'package:syncrow_web/utils/constants/api_const.dart';
import 'package:syncrow_web/utils/snack_bar.dart';
@ -18,7 +18,8 @@ class HTTPInterceptor extends InterceptorsWrapper {
];
@override
void onResponse(Response response, ResponseInterceptorHandler handler) async {
Future<void> onResponse(
Response response, ResponseInterceptorHandler handler) async {
if (await validateResponse(response)) {
super.onResponse(response, handler);
} else {
@ -28,26 +29,27 @@ class HTTPInterceptor extends InterceptorsWrapper {
}
@override
void onRequest(
Future<void> onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
var storage = const FlutterSecureStorage();
var token = await storage.read(key: Token.loginAccessTokenKey);
const storage = FlutterSecureStorage();
final token = await storage.read(key: Token.loginAccessTokenKey);
if (checkHeaderExclusionListOfAddedParameters(options.path)) {
options.headers
.putIfAbsent(HttpHeaders.authorizationHeader, () => "Bearer $token");
.putIfAbsent(HttpHeaders.authorizationHeader, () => 'Bearer $token');
}
// options.headers['Authorization'] = 'Bearer ${'${token!}123'}';
super.onRequest(options, handler);
}
@override
void onError(DioException err, ErrorInterceptorHandler handler) async {
ServerFailure failure = ServerFailure.fromDioError(err);
Future<void> onError(
DioException err, ErrorInterceptorHandler handler) async {
final failure = ServerFailure.fromDioError(err);
if (failure.toString().isNotEmpty) {
CustomSnackBar.displaySnackBar(failure.toString());
}
var storage = const FlutterSecureStorage();
var token = await storage.read(key: Token.loginAccessTokenKey);
const storage = FlutterSecureStorage();
final token = await storage.read(key: Token.loginAccessTokenKey);
if (err.response?.statusCode == 401 && token != null) {
// await AuthCubit.get(NavigationService.navigatorKey.currentContext!).logout();
}
@ -72,10 +74,10 @@ class HTTPInterceptor extends InterceptorsWrapper {
}
}
checkHeaderExclusionListOfAddedParameters(String path) {
bool shouldAddHeader = true;
bool checkHeaderExclusionListOfAddedParameters(String path) {
var shouldAddHeader = true;
for (var urlConstant in headerExclusionListOfAddedParameters) {
for (final urlConstant in headerExclusionListOfAddedParameters) {
if (path.contains(urlConstant)) {
shouldAddHeader = false;
}

View File

@ -8,10 +8,10 @@ class HTTPService {
// final navigatorKey = GlobalKey<NavigatorState>();
String certificateString = "";
String certificateString = '';
static Dio setupDioClient() {
Dio client = Dio(
final client = Dio(
BaseOptions(
baseUrl: ApiEndpoints.baseUrl,
receiveDataWhenStatusError: true,

View File

@ -17,34 +17,34 @@ class ServerFailure extends Failure {
factory ServerFailure.fromDioError(DioException dioError) {
switch (dioError.type) {
case DioExceptionType.connectionTimeout:
return ServerFailure("Connection timeout with the Server.");
return ServerFailure('Connection timeout with the Server.');
case DioExceptionType.sendTimeout:
return ServerFailure("Send timeout with the Server.");
return ServerFailure('Send timeout with the Server.');
case DioExceptionType.receiveTimeout:
return ServerFailure("Receive timeout with the Server.");
return ServerFailure('Receive timeout with the Server.');
case DioExceptionType.badCertificate:
return ServerFailure("Bad certificate!");
return ServerFailure('Bad certificate!');
case DioExceptionType.badResponse:
{
// var document = parser.parse(dioError.response!.data.toString());
// var message = document.body!.text;
return ServerFailure.fromResponse(dioError.response!.statusCode!,
dioError.response?.data['message'] ?? "Error");
return ServerFailure.fromResponse(dioError.response!.statusCode,
dioError.response?.data['message'] ?? 'Error');
}
case DioExceptionType.cancel:
return ServerFailure("The request to ApiServer was canceled");
return ServerFailure('The request to ApiServer was canceled');
case DioExceptionType.connectionError:
return ServerFailure("No Internet Connection");
return ServerFailure('No Internet Connection');
case DioExceptionType.unknown:
return ServerFailure("Unexpected Error, Please try again!");
return ServerFailure('Unexpected Error, Please try again!');
default:
return ServerFailure("Unexpected Error, Please try again!");
return ServerFailure('Unexpected Error, Please try again!');
}
}
@ -54,9 +54,9 @@ class ServerFailure extends Failure {
case 403:
return ServerFailure(responseMessage);
case 400:
List<String> errors = [];
final errors = <String>[];
if (responseMessage is List) {
for (var error in responseMessage) {
for (final error in responseMessage) {
errors.add(error);
}
} else {
@ -64,11 +64,11 @@ class ServerFailure extends Failure {
}
return ServerFailure(errors.join('\n'));
case 404:
return ServerFailure("");
return ServerFailure('');
case 500:
return ServerFailure(responseMessage);
default:
return ServerFailure("Opps there was an Error, Please try again!");
return ServerFailure('Opps there was an Error, Please try again!');
}
}
}