Closed helloalbin closed 2 years ago
When using FCM with riverpod,
Does the same error occur without riverpod ? If so, can you provide a complete minimal reproducible code sample that triggers the log ?
The same issue occures even without riverpod as well.
Code sample https://github.com/helloalbin/fcm_bug
Hi @helloalbin, I looked at your code sample and you seem to be using an older version of firebase_messaging
can you please try using the latest version firebase_messaging: ^11.4.1
?
Can you share what are the steps to reproduce the issue? I ran your code sample and tried pushing notifications and clicking them on IOS, but I don't see any error.
I tested with the latest version and the issue still exists. The updated dependencies are
firebase_core: ^1.17.1
firebase_analytics: ^9.1.9
firebase_crashlytics: ^2.8.1
dio_firebase_performance: ^0.3.1-dev.3
firebase_messaging: ^11.4.1
firebase_dynamic_links: ^4.2.5
firebase_remote_config: ^2.0.8
firebase_performance: ^0.7.1+5
firebase_in_app_messaging: ^0.6.0+15
cloud_firestore: ^3.1.17
The exception strack trace gets printed when we start the application. I am using Windows + Android 11 (API 30)
Output of flutter doctor
[√] Flutter (Channel stable, 3.0.0, on Microsoft Windows [Version 10.0.19042.1706], locale en-IN)
• Flutter version 3.0.0 at C:\Apps\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ee4e09cce0 (5 weeks ago), 2022-05-09 16:45:18 -0700
• Engine revision d1b9a6938a
• Dart version 2.17.0
• DevTools version 2.12.2
Thanks for the info @helloalbin, I was able to reproduce the error on Redmi k20 pro (Android 11), The error is reproduced by running the below code sample at this line
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {});
Launching lib/main.dart on Redmi K20 Pro in debug mode...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
W/FlutterActivityAndFragmentDelegate(17435): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
Connecting to VM Service at ws://127.0.0.1:59480/p9B2H3Jc_Vs=/ws
I/FIAM.Headless(17435): Successfully fetched 0 messages from backend
D/FRCPlugin(17435): Sending fetchTimeout: 60
I/flutter (17435): ----------------FIREBASE CRASHLYTICS----------------
I/flutter (17435): Null check operator used on a null value
I/flutter (17435): #0 MethodChannelFirebaseMessaging.registerBackgroundMessageHandler
I/flutter (17435): #1 FirebaseMessagingPlatform.onBackgroundMessage=
I/flutter (17435): #2 FirebaseMessaging.onBackgroundMessage
I/flutter (17435): #3 PushNotificationService.initialise
I/flutter (17435): #4 _MainStartViewState.initState
I/flutter (17435): #5 StatefulElement._firstBuild
I/flutter (17435): #6 ComponentElement.mount
I/flutter (17435): #7 Element.inflateWidget
I/flutter (17435): #8 Element.updateChild
I/flutter (17435): #9 RenderObjectToWidgetElement._rebuild
I/flutter (17435): ----------------------------------------------------
I/evercode.triag(17435): ProcessProfilingInfo new_methods=8939 is saved saved_to_disk=1 resolve_classes_delay=8000
E/FirebaseCrashlytics(17435): Cannot send reports. Timed out while fetching settings.
As per the documentation, you need to put the onBackgroundMessage function outside of a class, at the top of your file as a top-level function. See Firebase messaging example for implementation.
Bug report
Describe the bug When using FCM with riverpod, an error is thrown in the console.
Steps to reproduce
Follow the code provided in https://stackoverflow.com/questions/72038598/how-to-update-state-in-a-fcm-handler-with-statenotifierprovider.
My PushNotificationService
Error strack trace
Expected behavior
No error should be thrown
Flutter version 3.0.0