Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase messaging doesn't have a default constructor

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'.

like image 299
Franklin Premkumar Avatar asked Mar 27 '21 08:03

Franklin Premkumar


People also ask

What is the default constructor for the class firebasemessaging?

The class 'FirebaseMessaging' doesn't have a default constructor. The method 'configure' isn't defined for the type 'FirebaseMessaging'.

Is there an alternative to firebasemessaging's configure() function?

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 ).

What is Firebase Cloud Messaging (FCM)?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

How do I send messages to my customers using Firebase?

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.


Video Answer


2 Answers

Try FirebaseMessaging.instance instead of FirebaseMessaging(), it should work.

like image 59
Abu Saad Papa Avatar answered Oct 27 '22 10:10

Abu Saad Papa


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);
                    
        },
like image 23
Bijon Sharma Avatar answered Oct 27 '22 11:10

Bijon Sharma