title: firebase_messaging onBackgroundMessage local_notifications
body: <p>I'm trying to <strong>stop default notification</strong> from firebase_message when app is closed or on background.</p>
  <p>I want to show a custom Notification when app is closed or on background using local_notifications plugin, which works as expected, the problem resides when message is sent, app shows the same notification twice, 1 by default notification and the other with the custom notification.</p>
  <p>I can not achieve to stop default notification. Can anyone point out my mistake here?</p>
  <p>Initial code is from firebase messaging example removing unnecessary snippets and adding custom notification.</p>
  <p>Also attached an image of the current (bad behaviour)</p>
  <p><a href="https://i.stack.imgur.com/ye5MQ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ye5MQ.jpg" alt="enter image description here" /></a></p>
  <p>As stated before, same notification shown twice, want to get rid of the first one showed on the image.</p>
  <p>Here's my code:</p>
  <pre><code>// Copyright 2019 The Chromium Authors. All rights reserved.
  // Use of this source code is governed by a BSD-style license that can be
  // found in the LICENSE file.
  
  import 'dart:async';
  
  import 'package:firebase_core/firebase_core.dart';
  import 'package:firebase_messaging/firebase_messaging.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter_local_notifications/flutter_local_notifications.dart';
  import 'utils/utils.dart';
  
  Future&lt;void&gt; _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    print('_firebaseMessagingBackgroundHandler');
  
    Future onDidReceiveLocalNotification(
        int? id, String? title, String? body, String? payload) async {
      print('onDidReceiveLocalNotification');
    }
  
    final channel = AndroidNotificationChannel(
      'high_importance_channel', // id
      'High Importance Notifications', // title
      'This channel is used for important notifications.', // description
      importance: Importance.high,
    );
  
    var flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
  
    final initializationSettingsAndroid =
        AndroidInitializationSettings('icon_app');
    final initializationSettingsIOS = IOSInitializationSettings(
        onDidReceiveLocalNotification: onDidReceiveLocalNotification);
    final initializationSettingsMacOS = MacOSInitializationSettings();
  
    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation&lt;
            AndroidFlutterLocalNotificationsPlugin&gt;()
        ?.createNotificationChannel(channel);
    final initializationSettings = InitializationSettings(
        android: initializationSettingsAndroid,
        iOS: initializationSettingsIOS,
        macOS: initializationSettingsMacOS);
    await flutterLocalNotificationsPlugin.initialize(
      initializationSettings,
      onSelectNotification: onSelectNotification,
    );
  
    ///Not able to stop default notification
    ///there fore when custom notification is called
    ///result is 2 notifications displayed.
    NotificationDetails _notificationDetails;
    _notificationDetails = await customNotification(message: message);
    flutterLocalNotificationsPlugin.show(
      message.notification.hashCode,
      message.notification!.title,
      message.notification!.body,
      _notificationDetails,
      payload: '',
    );
  
    // await Firebase.initializeApp();
    print('Handling a background message ${message.messageId}');
  }
  
  Future&lt;NotificationDetails&gt; customNotification(
      {required RemoteMessage message}) async {
    print('notificationDetailsBigImage');
    final utils = Utils();
  
    final bigPicturePath = await utils.downloadAndSaveFile(
        url: 'https://picsum.photos/536/354', fileName: 'bigPicture');
    final bigPictureStyleInformation = BigPictureStyleInformation(
      FilePathAndroidBitmap(bigPicturePath),
      hideExpandedLargeIcon: true,
    );
    final androidPlatformChannelSpecifics = AndroidNotificationDetails(
      'big text channel name',
      'big text channel name',
      'big text channel description',
      styleInformation: bigPictureStyleInformation,
      icon: 'icon_app',
      color: const Color.fromARGB(255, 255, 0, 0),
      ledColor: const Color.fromARGB(255, 255, 0, 0),
      ledOnMs: 1000,
      ledOffMs: 500,
    );
    return NotificationDetails(android: androidPlatformChannelSpecifics);
  }
  
  Future&lt;void&gt; onDidReceiveLocalNotification(
      int? id, String? title, String? body, String? payload) async {
    print('onDidReceiveLocalNotification');
  }
  
  Future&lt;void&gt; onSelectNotification(String? payload) async {
    print('onSelectNotification');
  }
  
  Future&lt;void&gt; main() async {
    WidgetsFlutterBinding.ensureInitialized();
  
    await Firebase.initializeApp();
    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  
    await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
      alert: true,
      badge: true,
      sound: true,
    );
  
    runApp(MessagingExampleApp());
  }
  
  /// Entry point for the example application.
  class MessagingExampleApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Messaging Example App',
        theme: ThemeData.dark(),
        routes: {
          '/': (context) =&gt; Application(),
        },
      );
    }
  }
  
  /// Renders the example application.
  class Application extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; _Application();
  }
  
  class _Application extends State&lt;Application&gt; {
    late String _token;
  
    @override
    void initState() {
      super.initState();
      FirebaseMessaging.instance.getInitialMessage().then((message) {
        print('instance');
        if (message != null) {
          print('do stuff');
        }
      });
  
      FirebaseMessaging.onMessage.listen((message) {
        print('onMessage');
      });
  
      FirebaseMessaging.onMessageOpenedApp.listen((message) {
        print('A new onMessageOpenedApp event was published!');
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold();
    }
  }
  </code></pre>