'Error Flutter - The method 'configure' isn't defined for the type 'FirebaseMessaging'

when updating my App, the following error is appearing, can someone help me with my code?

Error: The method 'configure' isn't defined for the type 'FirebaseMessaging'. Try correcting the name to the name of an existing method, or defining a method named 'configure'.

Code:

import 'package:firebase_messaging/firebase_messaging.dart';

class PushNotification {
  final FirebaseMessaging _fcm = FirebaseMessaging.instance;

  
  Future initialize() async {
    _fcm.configure(
//      this callback is used when the app runs on the foreground
        onMessage: handleOnMessage,
//        used when the app is closed completely and is launched using the notification
        onLaunch: handleOnLaunch,
//        when its on the background and opened using the notification drawer
        onResume: handleOnResume);
  }

  Future handleOnMessage(Map<String, dynamic> data) async {
    print("=== data = ${data.toString()}");
  }

  Future handleOnLaunch(Map<String, dynamic> data) async {
    print("=== data = ${data.toString()}");
  }

  Future handleOnResume(Map<String, dynamic> data) async {
    print("=== data = ${data.toString()}");
  }
}


Solution 1:[1]

In the newest version of firebase_messaging, the configure method does not exists. You can see all possible methods in the official API reference.

I recommend checking the official Getting Started to have a compatible code with the latest version.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1