forked from eatvio/eatvio_app
28 lines
1.0 KiB
Dart
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,
|
|
),
|
|
);
|
|
}
|
|
}
|