0

下面是我的代码:

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);
}

代码对于单个通知工作正常,但是每当我向 android 发送多个通知时,它只会在状态栏中显示最后一个通知。

谁能帮助我了解如何使用颤振本地通知插件在状态栏中显示多个通知?

4

1 回答 1

0

如果你想对通知进行分组,flutter_local_notifications 中有一个选项可以做到这一点。为此,您可以在代码中添加以下内容

对于 ios:IOSNotificationDetails 中的线程标识符

对于 android:groupChannelId、groupChannelName、groupChannelDescription、

您可以在此处的文档中找到这些:https ://pub.dev/packages/flutter_local_notifications#displaying-a-notification 在“分组通知”下。

基本上相同threadId或groupId下的通知都会被分组显示

于 2021-07-21T07:43:53.700 回答