Files
eatvio_app/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart
2025-04-24 04:20:24 +07:00

28 lines
1.0 KiB
Dart

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<NotificationsState> {
final List<NotificationModel> _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<String, dynamic>;
// final notification = NotificationModel.fromJson(data);
// _notifications.add(notification);
emit(
NotificationsState.loaded(
notifications: _notifications,
notificationsCount: _notifications.length,
),
);
}
}