I got this error when I run my app and the background notifications when app is closed doesnt work:
firebase_messaging: ^7.0.3
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
@override
void initState() {
super.initState();
registerNotification();
}
void registerNotification() {
firebaseMessaging.requestNotificationPermissions();
firebaseMessaging.configure(onMessage: (Map<String, dynamic> message) {
print('onMessage: $message');
return ;
}, onResume: (Map<String, dynamic> message) {
print('onResume: $message');
return Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NotificationsScreen()));
}, onBackgroundMessage: _firebaseMessagingBackgroundHandler,
onLaunch: (Map<String, dynamic> message) {
print('onLaunch: $message');
return;
});
firebaseMessaging.getToken().then((token) {
print('token: $token');
FirebaseFirestore.instance
.collection('Consultant')
.doc(firebaseUser.uid)
.update({'deviceToken': token});
}).catchError((err) {
//Fluttertoast.showToast(msg: err.message.toString());
});
}
out from the class:
Future<dynamic> _firebaseMessagingBackgroundHandler(
Map<String, dynamic> message,
) async {
// Initialize the Firebase app
await Firebase.initializeApp();
print('onBackgroundMessage received: $message');
}
I got : ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(error, PluginRegistrantCallback is not set., null, java.lang.RuntimeException: PluginRegistrantCallback is not set.
The problem I figured out is when app is closed I can't get the notifications.
Searching on the internet I see that: PluginRegistrantCallback is not set
is an error which involve Application.kt class, but I tried in any manner to put this file unsuccesfully.
Any one has any suggestion?