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.
its a bug,
I confirm (firebase messaging 6.0.9, and flutter 1.12.13+hotfix.5)
but it happens only on Android, not iOS.
Guys
we need better firebase messaging for Android.
Many bugs, background data messages not working. Please allocate some time. It is important.
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.
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...
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 2cUpdate 2:
I created an empty project (using Java) with notification support, two times:1. with Android X support 2. withouth Android X supportBoth 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?
I have the same problem.
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
Hi @iapicca that's ok I will follow up that one.
Most helpful comment
Guys
we need better firebase messaging for Android.
Many bugs, background data messages not working. Please allocate some time. It is important.