Having a issue in flutter_local_notification library

36 Views Asked by At

I am having a issue in flutter_local_notifications: ^16.2.0 actually the problem is when i hit send a notification from the notification server then it's returning the two notification one is from firebase and another from the flutter local notification which is the same as firebase notification which i don't want so the problem is i just want a local notification not any other notification because i have a custom sound attached to the notification .

here is the code snippet

import 'dart:io';

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

 class LocalNotificationService {
  static final FlutterLocalNotificationsPlugin _notificationsPlugin =
      FlutterLocalNotificationsPlugin();

  static void initialize() {
    const iosInitializationSetting = DarwinInitializationSettings();

    const InitializationSettings initializationSettings = InitializationSettings(

      iOS: iosInitializationSetting,
      android: AndroidInitializationSettings("@mipmap/ic_launcher"),
    );

    _notificationsPlugin.initialize(initializationSettings,

      onDidReceiveNotificationResponse: (details) {
         debugPrint("onSelectNotification");
        String id = details.id.toString();
        if (id.isNotEmpty) {
           debugPrint("Router Value1234 $id");
        }
      },
    );
  }

  static void createAndDisplayNotification(RemoteMessage message) async {

    try {
      final id = DateTime
          .now()
          .millisecondsSinceEpoch ~/ 1000;

      // Check if the message type is "sos" to set the sound
      AndroidNotificationDetails androidNotificationDetails;
      const iosNotificationDetail = DarwinNotificationDetails(


          sound: 'custom_sound.wav', // Custom sound file name
      );

      NotificationDetails notificationDetails ;

        debugPrint("Message gg: ${message.data['type']}");

        androidNotificationDetails = const AndroidNotificationDetails(
          "pushNotificationPrsDriver11",
          "pushNotificationPrsDriver11",
          importance: Importance.max,
          priority: Priority.high,
          sound: RawResourceAndroidNotificationSound('custom_sound'),
          playSound: true,

          icon: '@mipmap/ic_launcher',

        );
        notificationDetails = NotificationDetails(
            android: androidNotificationDetails,iOS: iosNotificationDetail);




      await _notificationsPlugin.show(
        id,
        message.notification!.title,
        message.notification!.body,
        notificationDetails

      );
    } on Exception catch (e) {
      debugPrint(e.toString());
    }



  }



}
0

There are 0 best solutions below