Skip to content

[firebase_messaging] "onMessage" is triggered twice #1804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Celstren opened this issue Jan 12, 2020 · 9 comments
Closed

[firebase_messaging] "onMessage" is triggered twice #1804

Celstren opened this issue Jan 12, 2020 · 9 comments

Comments

@Celstren
Copy link

Hi everyone, I have been trying to implement firestore cloud messaging to an flutter app with the firebase_messaging package version 6.0.9 but each time that I try to send a test message to my app the "onMessage" event is triggered twice. I already follow all the basic steps to set up everything and it is working but the only problem is the messages displayed twice.

Here is my flutter doctor logs (I'm using Visual Studio Code)

[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Versión 10.0.17134.345], locale es-ES)
    • Flutter version 1.12.13+hotfix.5 at D:\flutter\flutter
    • Framework revision 27321ebbad (5 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\USER\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: D:\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at D:\Android Studio
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] IntelliJ IDEA Community Edition (version 2019.1)
    • IntelliJ at D:\IntelliJ IDEA Community Edition 2019.1.3
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[√] Connected device (1 available)
    • STK LX3 • 6JH4C19906011936 • android-arm64 • Android 9 (API 28)

! Doctor found issues in 1 category.

This is my main.dart code

import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyAppState();
  }
}

class _MyAppState extends State<MyApp> {
  String _message = '';

  final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

  _register() {
    _firebaseMessaging.getToken().then((token) => print(token));
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getMessage();
  }
  
  void getMessage(){
    _firebaseMessaging.configure(
        onMessage: (Map<String, dynamic> message) async {
      print('on message $message');
      setState(() => _message = message["notification"]["title"]);
    }, onResume: (Map<String, dynamic> message) async {
      print('on resume $message');
      setState(() => _message = message["notification"]["title"]);
    }, onLaunch: (Map<String, dynamic> message) async {
      print('on launch $message');
      setState(() => _message = message["notification"]["title"]);
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("Message: $_message"),
            OutlineButton(
              child: Text("Register My Device"),
              onPressed: () {
                _register();
              },
            ),
            // Text("Message: $message")
          ]),
        ),
      ),
    );
  }
}

If someone knows anything about this behaviour please let me know.

@rodrigolmacedo
Copy link

its a bug,
#1669
#1781

@scognito
Copy link

I confirm (firebase messaging 6.0.9, and flutter 1.12.13+hotfix.5)
but it happens only on Android, not iOS.

@nicksav
Copy link

nicksav commented Jan 15, 2020

Guys
we need better firebase messaging for Android.
Many bugs, background data messages not working. Please allocate some time. It is important.

@rodrigolmacedo
Copy link

Guys
we need better firebase messaging for Android.
Many bugs, background data messages not working. Please allocate some time. It is important.

for while, im doing my a work around, for detected duplicated messages, is annoying i know, but let them take a time to fix that and others things.

@scognito
Copy link

scognito commented Jan 15, 2020

Little update:
I'm using firebase_messaging 6.0.9 and firebase_core 0.4.3+2 on 2 projects.
Same code regarding notifications, on one app I have this bug, on the other I have not.
The only difference between them is the project based language. The "working" one is Java based, the "no working" is the Kotlin based.
Both project have same Gradle version, same imports, etc...
Maybe the problem is not related with this, just my 2c

Update 2:
I created an empty project (using Java) with notification support, two times:

  1. with Android X support
  2. withouth Android X support

Both have onMessage triggered twice, so I don't know where could be the problem...

@rodrigolmacedo
Copy link

Little update:
I'm using firebase_messaging 6.0.9 and firebase_core 0.4.3+2 on 2 projects.
Same code regarding notifications, on one app I have this bug, on the other I have not.
The only difference between them is the project based language. The "working" one is Java based, the "no working" is the Kotlin based.
Both project have same Gradle version, same imports, etc...
Maybe the problem is not related with this, just my 2c

Update 2:
I created an empty project (using Java) with notification support, two times:

1. with Android X support

2. withouth Android X support

Both have onMessage triggered twice, so I don't know where could be the problem...

here too, in other app(5.1.6) i dont face that bug, maybe the v2 embbeding get that error, you can debug for see what happening?

@CoderJava
Copy link

I have the same problem.

@iapicca
Copy link

iapicca commented Jan 21, 2020

Hi @Celstren
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca iapicca closed this as completed Jan 21, 2020
@Celstren
Copy link
Author

Hi @iapicca that's ok I will follow up that one.

@firebase firebase locked and limited conversation to collaborators Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants