Shreyansh Sharma
Shreyansh Sharma

Reputation: 1824

error: The method 'configure' isn't defined for the type 'FirebaseMessaging' in flutter

I wrote a code some time ago, now when I'm using it again, it shows me an error saying that configure isn't defined. Can someone edit this code, so it can be used in latest version of flutter? I tried changing some syntax bit can't convert the code.

Code-

_initFirebaseMessaging() {
    firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) {
        print('AppPushs onMessage : $message');
        _showNotification(message);
        return;
      },
      onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
      onResume: (Map<String, dynamic> message) {
        print('AppPushs onResume : $message');
        Navigator.pushNamed(context, message['data']['action']);

        return;
      },
      onLaunch: (Map<String, dynamic> message) {
        print('AppPushs onLaunch : $message');
        Navigator.pushNamed(context, message['data']['action']);

        return;
      },
    );
    // firebaseMessaging.requestNotificationPermissions(
    // const IosNotificationSettings(sound: true, badge: true, alert: true));
    firebaseMessaging.requestPermission(
      sound: true,
      alert: true,
      badge: true,
    );
  }

Upvotes: 1

Views: 5114

Answers (1)

jbyen
jbyen

Reputation: 1088

I think you are using the old method. Here is the new method:

My firebase_messaging package version is 10.0.1.

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      RemoteNotification notification = message.notification;
      showNotification(notification);
});

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      print("onMessageOpenedApp: $message");
});

FirebaseMessaging.onBackgroundMessage((RemoteMessage message) {
      print("onBackgroundMessage: $message");
});

Upvotes: 4

Related Questions