refactoring

This commit is contained in:
dahoud
2026-03-31 09:14:47 +00:00
parent 9bfffeeebe
commit 5383df6dcb
200 changed files with 11192 additions and 7063 deletions

View File

@@ -1,7 +1,9 @@
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:injectable/injectable.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../app/app.dart';
import '../config/environment.dart';
import '../di/injection.dart';
import '../error/error_handler.dart';
@@ -80,6 +82,10 @@ class ApiClient {
if (retryError.response?.statusCode == 401) {
debugPrint('🚪 [API] Persistent 401. Force Logout.');
_forceLogout();
return handler.reject(DioException(
requestOptions: retryError.requestOptions,
type: DioExceptionType.cancel,
));
}
return handler.next(retryError);
} catch (retryError) {
@@ -90,6 +96,10 @@ class ApiClient {
} else {
debugPrint('🚪 [API] Refresh failed. Force Logout.');
_forceLogout();
return handler.reject(DioException(
requestOptions: e.requestOptions,
type: DioExceptionType.cancel,
));
}
}
return handler.next(e);
@@ -100,6 +110,27 @@ class ApiClient {
void _forceLogout() {
try {
UnionFlowApp.scaffoldMessengerKey.currentState
?..clearSnackBars()
..showSnackBar(
SnackBar(
content: const Row(
children: [
Icon(Icons.lock_clock, color: Colors.white, size: 20),
SizedBox(width: 10),
Expanded(
child: Text(
'Session expirée. Vous avez été déconnecté automatiquement.',
style: TextStyle(color: Colors.white),
),
),
],
),
backgroundColor: Colors.orange.shade700,
duration: const Duration(seconds: 4),
behavior: SnackBarBehavior.floating,
),
);
final authBloc = getIt<AuthBloc>();
authBloc.add(const AuthLogoutRequested());
} catch (e, st) {