import 'package:eatvio_app/core/websockets/ws_manager.dart'; import 'package:eatvio_app/features/notifications/models/notification_model.dart'; import 'package:eatvio_app/features/notifications/presentation/notifications_cubit/notifications_state.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class NotificationsCubit extends Cubit { final List _notifications = []; final WsManager wsManager; NotificationsCubit({required this.wsManager}) : super(const NotificationsState.empty()) { wsManager.newNotificationsStream?.listen((event) { _handleNotification(event.data); }); } void _handleNotification(String notificationData) { // final data = jsonDecode(notificationData) as Map; // final notification = NotificationModel.fromJson(data); // _notifications.add(notification); emit( NotificationsState.loaded( notifications: _notifications, notificationsCount: _notifications.length, ), ); } }