简体   繁体   中英

The class 'FirebaseMessaging' doesn't have a default constructor I get this error after upgrading to Firebase massaging 10.0.4

Am getting the error on the FirebaseMessaging()

class PushNotificationService
{
 final FirebaseMessaging firebaseMessaging = FirebaseMessaging();

Am getting the error on the firebaseMessaging.configure

 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);
  },
);
}

In your case, you are initializing FirebaseMessaging like 'FirebaseMessaging()' when you should be initializing it by it's instance as specified here https://firebase.flutter.dev/docs/messaging/usage .

So, in your case you would use 'final FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance'.

Feel free to check out my example in my GitHub repo here: https://github.com/dchicchon/Polus/blob/master/app/lib/main.dart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM