diff --git a/example/lib/main.dart b/example/lib/main.dart index 589e961..3849820 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,10 +11,6 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { DitoSDK dito = DitoSDK(); dito.onBackgroundMessageHandler(message, apiKey: Constants.ditoApiKey, secretKey: Constants.ditoSecretKey); - dito.setOnMessageClick((data) { - print('app is in a terminated or background state'); - print(data.toJson()); - }); } void main() async { @@ -26,7 +22,6 @@ void main() async { apiKey: Constants.ditoApiKey, secretKey: Constants.ditoSecretKey); await dito.initializePushNotificationService(); dito.setOnMessageClick((data) { - print('app is open'); print(data.toJson()); }); diff --git a/package/lib/dito_sdk.dart b/package/lib/dito_sdk.dart index c937b7e..f82edb2 100644 --- a/package/lib/dito_sdk.dart +++ b/package/lib/dito_sdk.dart @@ -1,10 +1,10 @@ library dito_sdk; import 'package:dito_sdk/notification/notification_entity.dart'; +import 'package:dito_sdk/notification/notification_events.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:http/http.dart' as http; -import 'package:event_bus/event_bus.dart'; import 'data/dito_api.dart'; import 'event/event_entity.dart'; @@ -20,7 +20,7 @@ class DitoSDK { final UserInterface _userInterface = UserInterface(); final EventInterface _eventInterface = EventInterface(); final NotificationInterface _notificationInterface = NotificationInterface(); - EventBus eventBus = EventBus(); + final NotificationEvents _notificationEvents = NotificationEvents(); static final DitoSDK _instance = DitoSDK._internal(); @@ -49,7 +49,7 @@ class DitoSDK { } setOnMessageClick(Function(DataPayload) onMessageClicked) { - eventBus.on().listen((event) { + _notificationEvents.stream.on().listen((event) { onMessageClicked(event.data); }); } diff --git a/package/lib/notification/notification_events.dart b/package/lib/notification/notification_events.dart new file mode 100644 index 0000000..d985b0b --- /dev/null +++ b/package/lib/notification/notification_events.dart @@ -0,0 +1,22 @@ +import 'package:dito_sdk/notification/notification_entity.dart'; +import 'package:event_bus/event_bus.dart'; + +class MessageClickedEvent { + DataPayload data; + + MessageClickedEvent(this.data); +} + +class NotificationEvents { + EventBus eventBus = EventBus(); + + static final NotificationEvents _instance = NotificationEvents._internal(); + + factory NotificationEvents() { + return _instance; + } + + EventBus get stream => eventBus; + + NotificationEvents._internal(); +} diff --git a/package/lib/notification/notification_interface.dart b/package/lib/notification/notification_interface.dart index 8afac1a..39ce9ad 100644 --- a/package/lib/notification/notification_interface.dart +++ b/package/lib/notification/notification_interface.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:dito_sdk/notification/notification_events.dart'; import 'package:event_bus/event_bus.dart'; import 'package:flutter/foundation.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; @@ -11,18 +12,12 @@ import 'notification_entity.dart'; import 'notification_repository.dart'; import 'notification_controller.dart'; -class NotificationClickedEvent { - DataPayload data; - - NotificationClickedEvent(this.data); -} - /// NotificationInterface is an interface for communication with the notification repository and notification controller class NotificationInterface { final NotificationRepository _repository = NotificationRepository(); final NotificationController _controller = NotificationController(); + final NotificationEvents _notificationEvents = NotificationEvents(); final DitoApi _api = DitoApi(); - EventBus eventBus = EventBus(); /// The broadcast stream for received notifications final StreamController @@ -54,7 +49,7 @@ class NotificationInterface { _controller.showNotification(receivedNotification); }); _selectNotificationStream.stream.listen((DataPayload data) async { - eventBus.fire(NotificationClickedEvent(data)); + _notificationEvents.stream.fire(MessageClickedEvent(data)); final notificationId = data.notification; diff --git a/pubspec.yaml b/pubspec.yaml index ba234ae..d8cb633 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,4 +6,4 @@ environment: dev_dependencies: melos: ^6.0.0 dependencies: - event_bus: ^2.0.0 + event_bus: 2.0.0