Open timukasr opened 9 months ago
Thanks for the report @timukasr How are you sending the push notifications ? Can you try by using the plugin example script that uses node js and see if using it you still get same behavior as reported ?
Also, is this behavior occuring on physical device or using emulator ?
@darshankawar I tried with example script and I'm getting same behavior. I'm using physical device.
Please check if this is related to your case or not.
Does not seem to be exactly related, but found out that if i call await FirebaseMessaging.instance.getInitialMessage();
before FirebaseMessaging.onMessage.listen(onMessage);
, then everything works as expected (no old message during startup). If I get initial message after registering onMessage listener, then the issue occurs. Basically same thing as with await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions();
. So it seems that something is messed up there.
For me trying what @timukasr wrote above did not help. Same issue where the last message is re-delivered when app is opened from background or restarted.
class StubScreen extends StatefulWidget {
const StubScreen({super.key});
@override
State<StubScreen> createState() => _StubScreenState();
}
class _StubScreenState extends State<StubScreen> {
RemoteMessage? initialMessage;
@override
void initState() {
super.initState();
checkForMessage();
}
void checkForMessage() async {
final notification = await FirebaseMessaging.instance.getInitialMessage();
if (notification != null) {
checkMessage(notification);
}
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print('A new onMessageOpenedApp event was published!');
checkMessage(message);
});
}
void checkMessage(RemoteMessage? message) {
log('${message?.data.toString()}');
if (message != null && message.data['KEY'] != null) {
Navigator.push(...);
}
}
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
This is the most similar approach to the github implementation of this case.
firebase_core: ^2.15.1
firebase_messaging: ^14.7.9
Replicated on a physical device (Pixel 7 pro).
flutter doctor -v
output:
[β] Flutter (Channel stable, 3.13.9, on macOS 14.0 23A344 darwin-arm64, locale en-GB) β’ Flutter version 3.13.9 on channel stable at /Users/blinqipa/development/flutter β’ Upstream repository https://github.com/flutter/flutter.git β’ Framework revision d211f42860 (4 months ago), 2023-10-25 13:42:25 -0700 β’ Engine revision 0545f8705d β’ Dart version 3.1.5 β’ DevTools version 2.25.0 [β] Android toolchain - develop for Android devices (Android SDK version 33.0.1) β’ Android SDK at /Users/blinqipa/Library/Android/sdk β’ Platform android-34, build-tools 33.0.1 β’ Java binary at: /Applications/Android Studio Preview.app/Contents/jbr/Contents/Home/bin/java β’ Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) β’ All Android licenses accepted. [β] Xcode - develop for iOS and macOS (Xcode 15.0) β’ Xcode at /Applications/Xcode.app/Contents/Developer β’ Build 15A240d β’ CocoaPods version 1.14.3 [β] Chrome - develop for the web β’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (version unknown) β’ Android Studio at /Applications/Android Studio Preview.app/Contents β’ Flutter plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/9212-flutter β’ Dart plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/6351-dart β Unable to determine Android Studio version. β’ Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [β] VS Code (version 1.86.2) β’ VS Code at /Applications/Visual Studio Code.app/Contents β’ Flutter extension version 3.84.0 [β] Connected device (4 available) β’ Pixel 7 Pro (mobile) β’ 2A181FDH30064X β’ android-arm64 β’ Android 14 (API 34) β’ Blinβs iPhone (mobile) β’ 00008020-000B598A3C41402E β’ ios β’ iOS 17.4 21E217 β’ macOS (desktop) β’ macos β’ darwin-arm64 β’ macOS 14.0 23A344 darwin-arm64 β’ Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 122.0.6261.94 [β] Network resources β’ All expected network resources are available. ! Doctor found issues in 1 category.
Edit 2: Same issue persists with Flutter 3.19 and latest versions of firebase_core
and firebase_messaging
.
firebase_messaging: ^14.7.18
firebase_core: ^2.26.0
[β] Flutter (Channel stable, 3.19.2, on macOS 14.0 23A344 darwin-arm64, locale en-GB) β’ Flutter version 3.19.2 on channel stable at /Users/blinqipa/development/flutter β’ Upstream repository https://github.com/flutter/flutter.git β’ Framework revision 7482962148 (8 days ago), 2024-02-27 16:51:22 -0500 β’ Engine revision 04817c99c9 β’ Dart version 3.3.0 β’ DevTools version 2.31.1 [β] Android toolchain - develop for Android devices (Android SDK version 33.0.1) β’ Android SDK at /Users/blinqipa/Library/Android/sdk β’ Platform android-34, build-tools 33.0.1 β’ Java binary at: /Applications/Android Studio Preview.app/Contents/jbr/Contents/Home/bin/java β’ Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) β’ All Android licenses accepted. [β] Xcode - develop for iOS and macOS (Xcode 15.0) β’ Xcode at /Applications/Xcode.app/Contents/Developer β’ Build 15A240d β’ CocoaPods version 1.14.3 [β] Chrome - develop for the web β’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (version unknown) β’ Android Studio at /Applications/Android Studio Preview.app/Contents β’ Flutter plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/9212-flutter β’ Dart plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/6351-dart β Unable to determine Android Studio version. β’ Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [β] VS Code (version 1.86.2) β’ VS Code at /Applications/Visual Studio Code.app/Contents β’ Flutter extension version 3.84.0 [β] Connected device (4 available) β’ Pixel 7 Pro (mobile) β’ 2A181FDH30064X β’ android-arm64 β’ Android 14 (API 34) β’ Blinβs iPhone (mobile) β’ 00008020-000B598A3C41402E β’ ios β’ iOS 17.4 21E217 β’ macOS (desktop) β’ macos β’ darwin-arm64 β’ macOS 14.0 23A344 darwin-arm64 β’ Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 122.0.6261.94 [β] Network resources β’ All expected network resources are available. ! Doctor found issues in 1 category.
I think I'm encountering the same issue: when app opened getInitialMessage
returns and onMessageOpenedApp
emits same RemoteMessage
, causing user to be navigated to same route twice.
As far as I know, onMessageOpenedApp
should only emit RemoteMessage
s only when app is not killed.
Bug report
Describe the bug Main issue is that if foreground message is delivered via
FirebaseMessaging.onMessage.listen
, Android app is closed by pressing "Back" and re-opened by pressing app icon, thenonMessage.listen
is called again with latest message. Accidentally noticed, that if i callawait FirebaseMessaging.instance.setForegroundNotificationPresentationOptions();
before registering onMessage listener, then it works as expected (previous message is not delivered again). But I have Android app, sosetForegroundNotificationPresentationOptions
should not have this behavior. If this method is called after the onMessage listener is registered, then latest message is again re-delivered during app startup.Also noticed that, if
FirebaseMessaging.instance.getToken()
is not called, thenFirebaseMessaging.onMessage.listen
is also never called (even if I have active token).Steps to reproduce
Steps to reproduce the behavior:
Firebase.initializeApp
options in example app code.Also check other behaviors in
initState
:ifNoTokenAndNoSetOptions_thenNoMessages();
- no messages delivered at allifSetOptionsBefore_thenOk();
- hack to fix the issueifSetOptionsAfter_thenMessageRedelivered();
- hack does not work if called afteronMessage.listen
Expected behavior
"Messages" should be empty after app is opened
Sample project
Click To Expand
``` import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'config.dart'; FutureAdditional context
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
``` Doctor summary (to see all details, run flutter doctor -v): [!] Flutter (Channel stable, 3.19.1, on Microsoft Windows [Version 10.0.19045.3996], locale et-EE) ! Warning: `flutter` on your path resolves to J:\fvm\3.19.1\bin\flutter, which is not inside your current Flutter SDK checkout at J:\fvm\default. Consider adding J:\fvm\default\bin to the front of your path. ! Warning: `dart` on your path resolves to J:\fvm\3.19.1\bin\dart, which is not inside your current Flutter SDK checkout at J:\fvm\default. Consider adding J:\fvm\default\bin to the front of your path. [β] Windows Version (Installed version of Windows is version 10 or higher) [β] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [β] Chrome - develop for the web [β] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.3) [β] Android Studio (version 2023.1) [β] IntelliJ IDEA Ultimate Edition (version 2023.3) [β] VS Code (version 1.86.2) [β] Connected device (4 available) [β] Network resources ! Doctor found issues in 1 category. ```Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
``` Dart SDK 3.3.0 Flutter SDK 3.19.1 flutter_fcm 1.0.0+1 dependencies: - cupertino_icons 1.0.6 - firebase_core 2.25.5 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.7.17 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] dev dependencies: - flutter_lints 3.0.1 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service] transitive dependencies: - _flutterfire_internals 1.3.23 [collection firebase_core firebase_core_platform_interface flutter meta] - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - clock 1.1.1 - collection 1.18.0 - fake_async 1.3.1 [clock collection] - firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.11.5 [firebase_core_platform_interface flutter flutter_web_plugins js meta web] - firebase_messaging_platform_interface 4.5.25 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.6.6 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta web] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math] - js 0.6.7 [meta] - leak_tracker 10.0.0 [clock collection meta path vm_service] - leak_tracker_flutter_testing 2.0.1 [flutter leak_tracker leak_tracker_testing matcher meta] - leak_tracker_testing 2.0.1 [leak_tracker matcher meta] - lints 3.0.0 - matcher 0.12.16+1 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.8.0 [collection] - meta 1.11.0 - path 1.9.0 - plugin_platform_interface 2.1.8 [meta] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - stack_trace 1.11.1 [path] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.6.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - vector_math 2.1.4 - vm_service 13.0.0 - web 0.4.2 ```