36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
library notifications_page_wrapper;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import '../../../../core/di/injection.dart';
|
|
import '../../../../core/utils/logger.dart';
|
|
import '../../data/repositories/notification_repository.dart';
|
|
import '../bloc/notifications_bloc.dart';
|
|
import 'notifications_page.dart';
|
|
|
|
/// Wrapper qui fournit le NotificationsBloc à la NotificationsPage
|
|
class NotificationsPageWrapper extends StatelessWidget {
|
|
const NotificationsPageWrapper({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider<NotificationsBloc>(
|
|
create: (_) => _getOrCreateNotificationsBloc(),
|
|
child: const NotificationsPage(),
|
|
);
|
|
}
|
|
|
|
static NotificationsBloc _getOrCreateNotificationsBloc() {
|
|
try {
|
|
if (GetIt.instance.isRegistered<NotificationsBloc>()) {
|
|
return GetIt.instance<NotificationsBloc>();
|
|
}
|
|
} catch (e, st) {
|
|
AppLogger.error('NotificationsPageWrapper: résolution NotificationsBloc échouée', error: e, stackTrace: st);
|
|
}
|
|
final repo = getIt<NotificationRepository>();
|
|
return NotificationsBloc(repo);
|
|
}
|
|
}
|