[英]How to display multiple notifications using flutter plugin : flutter_local_notifications
Here is my code below :这是我的代码如下:
const AndroidNotificationChannel notificationChannel = AndroidNotificationChannel(
'high_importance_channel',
'high importance Notificaion',
'this channel is used for import notification',
importance: Importance.high,
playSound: true,
);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
Future<void> firebaseBackgroundMessageHandler(RemoteMessage message) async {
await firebaseMessageHandler(message);
}
Future<void> firebaseForegroundMessageHandler(RemoteMessage message) async {
await firebaseMessageHandler(message);
}
Future<void> firebaseMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
try {
flutterLocalNotificationsPlugin.show(
message.notification.hashCode,
message.data["title"].toString(),
message.data["body"].toString(),
NotificationDetails(
android: AndroidNotificationDetails(notificationChannel.id, notificationChannel.name, notificationChannel.description),
));
} catch (_err) {}
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(firebaseBackgroundMessageHandler);
FirebaseMessaging.onMessage.listen(firebaseForegroundMessageHandler);
//FirebaseMessaging.onMessageOpenedApp.listen(firebaseMessageHandler);
final AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('e_app');
final InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()?.createNotificationChannel(notificationChannel);
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(alert: true, badge: true, sound: true);
}
Code is working fine for a single notification but whenever i send multiple notifications to android, it shows only last notification in status bar.代码对于单个通知工作正常,但是每当我向 android 发送多个通知时,它只在状态栏中显示最后一个通知。
Could any one help me about how to show multiple notifications in status bar using flutter local notification plugin ?有人可以帮助我了解如何使用 Flutter 本地通知插件在状态栏中显示多个通知吗?
If you want to group your notifications, there is an option to do that in flutter_local_notifications.如果您想对通知进行分组,可以在 flutter_local_notifications 中选择这样做。 To do this, you can add the following in your code
为此,您可以在代码中添加以下内容
for ios : threadIdentifier in IOSNotificationDetails对于 ios :IOSNotificationDetails 中的 threadIdentifier
for android : groupChannelId, groupChannelName, groupChannelDescription,安卓:groupChannelId、groupChannelName、groupChannelDescription、
You can find these in the docs here: https://pub.dev/packages/flutter_local_notifications#displaying-a-notification under 'Grouping notifications'.您可以在此处的文档中找到这些: https : //pub.dev/packages/flutter_local_notifications#displaying-a-notification在“分组通知”下。
Basically notifications under same threadId or groupId will all be grouped and shown基本上相同 threadId 或 groupId 下的通知都将被分组并显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.