refactoring
This commit is contained in:
@@ -32,6 +32,7 @@ class NotificationFeedRepository {
|
||||
.map((json) => _itemFromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return [];
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ class NotificationRepositoryImpl implements NotificationRepository {
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return [];
|
||||
rethrow;
|
||||
}
|
||||
@@ -51,6 +52,7 @@ class NotificationRepositoryImpl implements NotificationRepository {
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return [];
|
||||
rethrow;
|
||||
}
|
||||
@@ -69,6 +71,7 @@ class NotificationRepositoryImpl implements NotificationRepository {
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return [];
|
||||
rethrow;
|
||||
}
|
||||
@@ -87,6 +90,7 @@ class NotificationRepositoryImpl implements NotificationRepository {
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return [];
|
||||
rethrow;
|
||||
}
|
||||
@@ -101,6 +105,7 @@ class NotificationRepositoryImpl implements NotificationRepository {
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return null;
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@@ -21,6 +22,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
|
||||
final items = await _repository.getNotifications();
|
||||
emit(NotificationLoaded(items: items));
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('NotificationBloc: chargement notifications échoué', error: e, stackTrace: st);
|
||||
emit(NotificationError('Erreur de chargement: $e'));
|
||||
}
|
||||
@@ -46,6 +48,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
|
||||
}).toList();
|
||||
emit(NotificationLoaded(items: updatedItems));
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('NotificationBloc: marquer comme lu échoué', error: e, stackTrace: st);
|
||||
emit(NotificationError('Impossible de marquer comme lu'));
|
||||
}
|
||||
|
||||
@@ -33,8 +33,10 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
|
||||
final nonLues = notifications.where((n) => !n.estLue).length;
|
||||
emit(NotificationsLoaded(notifications: notifications, nonLuesCount: nonLues));
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) return;
|
||||
emit(NotificationsError(_networkError(e)));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(NotificationsError('Erreur lors du chargement : $e'));
|
||||
}
|
||||
}
|
||||
@@ -70,6 +72,7 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
|
||||
emit(NotificationMarkedAsRead(notifications: updated, nonLuesCount: nonLues));
|
||||
}
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('NotificationsBloc: marquer comme lu échoué', error: e, stackTrace: st);
|
||||
emit(NotificationsError('Impossible de marquer comme lu'));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF8F9FA),
|
||||
backgroundColor: AppColors.lightBackground,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
@@ -101,8 +101,8 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
/// Header harmonisé avec le design system
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.all(16),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [AppColors.brandGreen, AppColors.primaryGreen],
|
||||
@@ -169,7 +169,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
/// Barre d'onglets
|
||||
Widget _buildTabBar() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightSurface,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -196,8 +196,8 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
Widget _buildNotificationsTab() {
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Filtres et options
|
||||
_buildFiltersSection(),
|
||||
|
||||
@@ -212,7 +212,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
/// Section filtres
|
||||
Widget _buildFiltersSection() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -436,7 +436,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Notifications push
|
||||
_buildPreferenceSection(
|
||||
@@ -661,7 +661,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
case 'Membres':
|
||||
return AppColors.primaryGreen;
|
||||
case 'Événements':
|
||||
return const Color(0xFF00B894);
|
||||
return AppColors.success;
|
||||
case 'Organisations':
|
||||
return AppColors.primaryGreen;
|
||||
case 'Système':
|
||||
@@ -797,7 +797,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
_tabController.animateTo(1); // Aller à l'onglet Préférences
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF6C5CE7),
|
||||
backgroundColor: AppColors.primaryGreen,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Voir les préférences'),
|
||||
@@ -858,13 +858,13 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE17055).withOpacity(0.1),
|
||||
color: AppColors.warning.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'Action disponible : ${notification['actionText']}',
|
||||
style: const TextStyle(
|
||||
color: Color(0xFFE17055),
|
||||
color: AppColors.warning,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -883,7 +883,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
_showSuccessSnackBar('Action "${notification['actionText']}" exécutée');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFE17055),
|
||||
backgroundColor: AppColors.warning,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: Text(notification['actionText']),
|
||||
@@ -908,7 +908,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: const Color(0xFF00B894),
|
||||
backgroundColor: AppColors.success,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
@@ -919,7 +919,7 @@ class _NotificationsPageState extends State<NotificationsPage>
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
backgroundColor: AppColors.error,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user