A plugin that allows you to handle notifications from Sendbird in your Flutter app.
Push Notifications sent by Sendbird lacks visibility in the app. It uses FCM and APNS under the hood, On IOS you can't interact with the notifications or receive them in the foreground. On Android you can receive them in the foreground or when the app is launched by tapping on them using firebase_messaging, but they don't show in the background because Sendbird only sends a data message. This plugin handle the complete the missing pieces without having to write native code. It's designed to work side by side with firebase_messaging, not as a replacement.
- Receive notification when app is in foreground
- Handle when a notification is tapped when the app is in background (Running)
- Handle when a notification is tapped when the app is terminated
- Show a notification when the app is in the background (Running or Terminated)
- Listens for when a notification was tapped when the app is in background (Running)
- Handle when a notification is tapped when the app is terminated
add the following to your pubspec.yaml file:
dependencies:
sendbird_notification_handler: <latest_version>
Note: Push Notifications on IOS are received only on Physical devices, not on the simulator.
import 'package:sendbird_notification_handler/sendbird_notification_handler.dart';
SendbirdNotificationHandler.onMessageOpened.listen((message) {
// Navigate to a chat screen
});
import 'package:sendbird_notification_handler/sendbird_notification_handler.dart';
final message = await SendbirdNotificationHandler.getInitialMessage();
if(message != null) {
// Redirect to the chat screen
}
import 'package:sendbird_notification_handler/sendbird_notification_handler.dart';
SendbirdNotificationHandler.onMessageReceived.listen((message) {
// Show a snackbar, Update messages count, etc
});
Use FirebaseMessaging#onMessage and check for sendbird object in Android
Show a notification when the app is in the background (Android only, for IOS it shows automatically)
This should be tested with a real message not the test notification from the Sendbird dashboard as It has a different structure.
import 'package:sendbird_notification_handler/sendbird_notification_handler.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
FirebaseMessaging.onBackgroundMessage(initBackgroundNotificationsHandler);
@pragma('vm:entry-point')
Future<void> initBackgroundNotificationsHandler(RemoteMessage message) async {
final isSendbirdMessage = message.data.containsKey('sendbird');
if (!isSendbirdMessage) {
return;
}
SendbirdNotificationHandler.sendNotification(
payload: message.data,
);
}
This plugin wouldn't have been possible without the huge support from Trim
- Show sender avatar in the notification
- Add support for reply action
- Add support for mark as read action
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.