import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class PushNotificationService
{
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
Future initialize(context) async
{
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
},
onLaunch: (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
},
onResume: (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
},
);
}
Manifest:
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT"
/>
</intent-filter>
Error: The class 'FirebaseMessaging' doesn't have a default constructor. Try using one of the named constructors defined in 'FirebaseMessaging'.
The class 'FirebaseMessaging' doesn't have a default constructor. The method 'configure' isn't defined for the type 'FirebaseMessaging'.
It's pretty straightforward. in the latest firebase_messaging plugin ( ^7.0.3 ), the FirebaseMessaging class doesn't have configure () function. any other alternative? Actually it was removed in the prerelease version that came after 7.0.3 ( 8.0.0-dev.1 ).
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
You can send messages via the Firebase Admin SDK or the FCM server protocols. For testing or for sending marketing or engagement messages with powerful built-in targeting and analytics, you can also use the Notifications composer.
Try FirebaseMessaging.instance
instead of FirebaseMessaging()
, it should work.
try to add add dependencies firebase_core 1.4.0
import 'package:firebase_core/firebase_core.dart';
@override
void initState() {
// TODO: implement initState
super.initState();
Firebase.initializeApp();
}
onPressed: () async {
String token = await FirebaseMessaging.instance.getToken();
print(token);
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With