title: Double Notifications in Flutter firebase messaging
body: <p>Recently I upgraded to firebase_messaging: ^10.0.0 When app is in not running and if notification comes it is displaying twice. I modified the notification data in code after receiving and displayed it. Even then I can see the modified and non modified notifications. I don't know where that notification is triggering. But when app is running it is displaying notification once only(works fine). Here goes my code</p>
  <pre><code>/*main.dart*/
  Future&lt;void&gt; firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    // If you're going to use other Firebase services in the background, such as Firestore,
    // make sure you call `initializeApp` before using other Firebase services.
    //await Firebase.initializeApp();
  
    // await HomePageState.handleMessage(message);
    String title=&quot;${message.notification!.title}&quot;;
    String body=&quot;${message.notification!.body}&quot;;
  
    _flutterLocalNotificationsPlugin.show(0, title, body, platformChannelSpecifics, payload: jsonEncode(message.data));
  
    AppDatabase database= await $FloorAppDatabase.databaseBuilder(Constants.dataBaseName).addMigrations([migration1to2]).build();
    if(!title.toLowerCase().contains(&quot;cancelled&quot;)){
      var date=DateFormat(&quot;dd-MMM-yyyy hh:mm aa&quot;).format(DateTime.now());
      NotificationModel notification=NotificationModel(title: title,message: body,read: 0,date: date);
      await database.notificationDao.insertNotification(notification);
    }
  
    print(&quot;Handling a background message: ${message.messageId}&quot;);
  }
  Future&lt;void&gt; main() async {
    //this line make sure all the required widgets are loaded before main application starts
    //SharedPreferences.setMockInitialValues({});
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
  
    var initializationSettingsAndroid = new AndroidInitializationSettings('@mipmap/ic_notification');
    var initializationSettingsIOS = new IOSInitializationSettings(onDidReceiveLocalNotification: onDidReceiveLocalNotification);
    //var initializationSettings = new InitializationSettings(initializationSettingsAndroid, initializationSettingsIOS);
    var initializationSettings = new InitializationSettings(android: initializationSettingsAndroid,iOS: initializationSettingsIOS);
    _flutterLocalNotificationsPlugin.initialize(initializationSettings,onSelectNotification: onSelectingNotification);
  
    FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
  
  
    //Initializing repository and carrying forward to avoid multiple instances of database
    Repository _repository = Repository();
  
    // runApp(BlocProvider(
    //   create: (_) =&gt; ThemeBloc()..add(ThemeLoadStarted()),
    //   child: MyApp(
    //     repository: _repository,
    //   ),
    // ));
    SentryOptions options=SentryOptions(dsn: APIs.sentryAPI);
    final SentryClient _sentry = SentryClient(options);
  
    Future&lt;void&gt; _reportErrorToSentry(dynamic error, dynamic stackTrace) async {
      // Print the exception to the console.
      print('Caught error: $error');
     await  _sentry.captureException(
        error,
        stackTrace: stackTrace,
      );
    }
  
    runZonedGuarded(() async{
      // runApp(BlocProvider(
      //   create: (_) =&gt; ThemeBloc()..add(ThemeLoadStarted()),
      //   child: MyApp(
      //     repository: _repository,
      //   ),
      // ));
  
      await SentryFlutter.init(
            (options) =&gt; options.dsn = APIs.sentryAPI,
        appRunner: () =&gt; runApp(BlocProvider(
          create: (_) =&gt; ThemeBloc()..add(ThemeLoadStarted()),
          child: MyApp(
            repository: _repository,
          ),
        )),
      );
    }, (error, stackTrace) {
      print('runZonedGuarded: Caught error in my root zone.');
      FirebaseCrashlytics.instance.recordError(error, stackTrace);
      _reportErrorToSentry(error,stackTrace);
    });
  
  }
  </code></pre>
  <p>Application.kt</p>
  <pre><code>import io.flutter.app.FlutterApplication
  import io.flutter.plugin.common.PluginRegistry
  import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
  import io.flutter.plugins.GeneratedPluginRegistrant
  import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService
  
  
  class Application : FlutterApplication(), PluginRegistrantCallback {
  
      override fun registerWith(registry: PluginRegistry) {
          //FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
          FlutterLocalNotificationPluginRegistrant.registerWith(registry)
          SqflitePluginRegistrant.registerWith(registry)
      }
  }
  </code></pre>
  <p>FirebaseCloudMessagingPluginRegistrant.kt which I commented out in application.kt</p>
  <pre><code>import io.flutter.plugin.common.PluginRegistry
  import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin
  class FirebaseCloudMessagingPluginRegistrant {
      companion object {
          fun registerWith(registry: PluginRegistry) {
              if (alreadyRegisteredWith(registry)) {
                  return
              }
              FlutterFirebaseMessagingPlugin.registerWith(registry.registrarFor(&quot;io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin&quot;))
          }
  
          fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
              val key = FirebaseCloudMessagingPluginRegistrant::class.java.name
              if (registry.hasPlugin(key)) {
                  return true
              }
              registry.registrarFor(key)
              return false
          }
      }
  }
  </code></pre>
  <p>AndroidManifest.xml</p>
  <pre><code>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      package=&quot;**.***.***tomer&quot;&gt;
      &lt;!-- io.flutter.app.FlutterApplication is an android.app.Application that
           calls FlutterMain.startInitialization(this); in its onCreate method.
           In most cases you can leave this as-is, but you if you want to provide
           additional functionality it is fine to subclass or reimplement
           FlutterApplication and put your custom class here. --&gt;
  
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  &lt;!--    &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;--&gt;
  &lt;!--    android:label=&quot;@string/app_label&quot;--&gt;
      &lt;application
          android:name=&quot;.Application&quot;
          android:label=&quot;Zuzu&quot;
          android:usesCleartextTraffic=&quot;true&quot;
          android:networkSecurityConfig=&quot;@xml/network_security_config&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;&gt;
          &lt;meta-data android:name=&quot;io.flutter.network-policy&quot;
              android:resource=&quot;@xml/network_security_config&quot;/&gt;
          &lt;activity
              android:name=&quot;.MainActivity&quot;
              android:launchMode=&quot;singleTop&quot;
              android:theme=&quot;@style/LaunchTheme&quot;
              android:configChanges=&quot;orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode&quot;
              android:hardwareAccelerated=&quot;true&quot;
              android:windowSoftInputMode=&quot;adjustResize&quot;
              tools:targetApi=&quot;n&quot;&gt;
  
              &lt;!-- Specifies an Android theme to apply to this Activity as soon as
                   the Android process has started. This theme is visible to the user
                   while the Flutter UI initializes. After that, this theme continues
                   to determine the Window background behind the Flutter UI. --&gt;
              &lt;meta-data
                android:name=&quot;io.flutter.embedding.android.NormalTheme&quot;
                android:resource=&quot;@style/NormalTheme&quot;
                /&gt;
              &lt;!-- Displays an Android View that continues showing the launch screen
                   Drawable until Flutter paints its first frame, then this splash
                   screen fades out. A splash screen is useful to avoid any visual
                   gap between the end of Android's launch screen and the painting of
                   Flutter's first frame. --&gt;
              &lt;meta-data
                android:name=&quot;io.flutter.embedding.android.SplashScreenDrawable&quot;
                android:resource=&quot;@drawable/launch_background&quot;
                /&gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;!-- Don't delete the meta-data below.
               This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --&gt;
          &lt;meta-data
              android:name=&quot;flutterEmbedding&quot;
              android:value=&quot;2&quot; /&gt;
          &lt;meta-data android:name=&quot;com.google.android.geo.API_KEY&quot;
              android:value=&quot;AIzaSyBqZ4aa************GMzHpofWKeEU&quot;/&gt;
          &lt;meta-data android:name=&quot;com.facebook.sdk.ApplicationId&quot; android:value=&quot;@string/facebook_app_id&quot;/&gt;
  
          &lt;meta-data
              android:name=&quot;com.google.firebase.messaging.default_notification_channel_id&quot;
              android:value=&quot;Zuzu&quot; /&gt;
          &lt;meta-data android:name=&quot;com.google.firebase.messaging.default_notification_icon&quot;
              android:resource=&quot;@mipmap/ic_notification&quot;/&gt;
          &lt;meta-data android:name=&quot;com.google.firebase.messaging.default_notification_color&quot;
              android:resource=&quot;@color/notification&quot;/&gt;
  
          &lt;activity
              android:name=&quot;com.yalantis.ucrop.UCropActivity&quot;
              android:screenOrientation=&quot;portrait&quot;
              android:theme=&quot;@style/Theme.AppCompat.Light.NoActionBar&quot;/&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/XKXxM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XKXxM.jpg" alt="enter image description here" /></a>
  This issue is in android only that too when app is not running. Where am I doing wrong?</p>