diff --git a/lib/src/platform/src/method_call_handler.dart b/lib/src/platform/src/method_call_handler.dart index 566ee9f0f..ac05625d8 100644 --- a/lib/src/platform/src/method_call_handler.dart +++ b/lib/src/platform/src/method_call_handler.dart @@ -94,7 +94,7 @@ class AblyMethodCallHandler { } Future _onPushBackgroundMessage(RemoteMessage remoteMessage) async { - _pushNotificationEvents.handleBackgroundMessage(remoteMessage); + await _pushNotificationEvents.handleBackgroundMessage(remoteMessage); return null; } diff --git a/lib/src/platform/src/push_notification_events_internal.dart b/lib/src/platform/src/push_notification_events_internal.dart index 9782cc740..a00e42193 100644 --- a/lib/src/platform/src/push_notification_events_internal.dart +++ b/lib/src/platform/src/push_notification_events_internal.dart @@ -81,9 +81,14 @@ class PushNotificationEventsInternal implements PushNotificationEvents { /// @nodoc /// Handles a RemoteMessage passed from the platform side. - void handleBackgroundMessage(RemoteMessage remoteMessage) { + Future handleBackgroundMessage(RemoteMessage remoteMessage) async { if (_onBackgroundMessage != null) { - _onBackgroundMessage!(remoteMessage); + final onBackgroundMessageResult = _onBackgroundMessage!(remoteMessage); + // ^^^ _onBackgroundMessage() can return void or Future + if (onBackgroundMessageResult is Future) { + // if it returns a Future we await on it. + await onBackgroundMessageResult; + } } else { // ignore:avoid_print print('Received RemoteMessage but no handler was set. ' diff --git a/lib/src/push_notifications/src/push_notification_events.dart b/lib/src/push_notifications/src/push_notification_events.dart index bdd939ed8..f36ff76ea 100644 --- a/lib/src/push_notifications/src/push_notification_events.dart +++ b/lib/src/push_notifications/src/push_notification_events.dart @@ -4,7 +4,7 @@ import 'package:ably_flutter/ably_flutter.dart'; /// Type definition for a callback invoked when background push message /// is received. -typedef BackgroundMessageHandler = void Function(RemoteMessage message); +typedef BackgroundMessageHandler = dynamic Function(RemoteMessage message); /// Push Notification events, such as message arriving or notification tap. abstract class PushNotificationEvents {