Unhandled Exception: Null check operator used on a null value on firebase messaging #11337
Unanswered
daphneyong11
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to use local notification and firebase messaging for prompt notification.
However, I noticed an error come out in the terminal record (Still can show notification on foreground, background and terminated on Android.)
In debug mode, the notification is running great, but in release mode, the custom sound is not played and when in foreground, the icon data is missing too. I am not sure is this error causing the problem, or my coding is wrong.
This is the error code shown:
E/flutter ( 9896): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter ( 9896): #0 MethodChannelFirebaseMessaging.registerBackgroundMessageHandler (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:181:53)
E/flutter ( 9896): #1 FirebaseMessagingPlatform.onBackgroundMessage= (package:firebase_messaging_platform_interface/src/platform_interface/platform_interface_messaging.dart:102:16)
E/flutter ( 9896): #2 FirebaseMessaging.onBackgroundMessage (package:firebase_messaging/src/messaging.dart:73:31)
E/flutter ( 9896): #3 FirebaseApi.initNotifications (package:linxpetmobile/api/firebase_api.dart:33:23)
E/flutter ( 9896):
E/flutter ( 9896): #4 main (package:linxpetmobile/main.dart:19:3)
E/flutter ( 9896):
E/flutter ( 9896):
Below is the main dart code that trigger the firebase_api.dart code:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseApi().initNotifications();
runApp(MyWebView());
}
And below is the firebase_api.dart code
import 'dart:convert';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class FirebaseApi {
final _firebaseMessaging = FirebaseMessaging.instance;
final FlutterLocalNotificationsPlugin _localNotifications = FlutterLocalNotificationsPlugin();
FirebaseApi() {
// Initialize the FlutterLocalNotificationsPlugin
_initializeLocalNotifications();
}
// Initialize FlutterLocalNotificationsPlugin
void _initializeLocalNotifications() {
const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('launcher_icon');
final InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid);
_localNotifications.initialize(initializationSettings);
}
Future initNotifications() async {
await _firebaseMessaging.requestPermission();
}
Future handleFirebaseMessage(RemoteMessage message) async {
var notification = message.notification;
if (notification == null) return;
}
}
Beta Was this translation helpful? Give feedback.
All reactions