简体   繁体   English

如何使用flutter插件显示多个通知:flutter_local_notifications

[英]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.

相关问题 使用 flutter_local_notifications 安排通知 - Schedule notification using flutter_local_notifications 计划通知未显示(Flutter_local_notifications) - scheduled notifications not showing (Flutter_local_notifications) Flutter - 使用 flutter_local_notifications 轻松显示 AndroidNotification? - Flutter - Display AndroidNotification easily with flutter_local_notifications? 使用 flutter_local_notifications 插件时,挂起的通知在重启后被取消 - When using the flutter_local_notifications plugin, pending notifications are cancelled after a reboot flutter_local_notifications onNotificationReceived 方法 - Flutter - flutter_local_notifications onNotificationReceived method - Flutter flutter_local_notifications 插件未在通知中显示大图像 - flutter_local_notifications plugin not showing the big image in notification flutter_local_notifications 对我不起作用 - flutter_local_notifications not working for me flutter_local_notifications 路由全屏 - flutter_local_notifications route fullscreen 有没有办法使用 flutter_local_notifications 跳过重复通知? - Is there a way to skip a recurring notification using flutter_local_notifications? 如何铸造未来<null>到未来<dynamic>在 Flutter 中使用flutter_local_notifications?</dynamic></null> - How to cast Future<Null> to Future<dynamic> in Flutter while using flutter_local_notifications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM