Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am a newbie to flutter. I just upgraded a project built for me to flutter 2.0 and I am not certain how to resolve this particular issue. I have googled and found examples. I understand there is improvement here which potentially resolves one of the issues my app was facing. But I do not know enough to know how to adjust this particular section of code because it is more complicated than any examples I can find online. Hoping someone can point me in the right direction.

void initFCMNotification() {
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        mapEntry = message;
        String type =
            message['Notificationtype'] ?? message['data']['Notificationtype'];
        print("notification onMessage $type");

        if (type == '5' || type == '11' || type == '3') {
          Function reload = context.read<EventsProvider>().reload;
          Future.delayed(Duration(seconds: 1), () {
            reload(true);
          });
        } else if (type == '4') {
          var notification = getNotification(message);
          nav.currentState.push(MaterialPageRoute(
              builder: (context) => MeetAgainScreen(notification)));
        }
        if (type != '11') {
          if (Platform.isIOS) {
            notiType = message['Notificationtype'];
            print('isIOS on message ${message['aps']['alert']['title']}');
            if (type == "0") {
              reloadData(type, message);
            } else {
              showSilentNotification(flutterLocalNotificationsPlugin,
                  title:
                      "${message['title'] ?? message['aps']['alert']['title'] ?? message['notification']['title'] ?? ''}",
                  payload: "${message['Notificationtype'] ?? ''}",
                  body:
                      "${message['body'] ?? message['aps']['alert']['body'] ?? message['notification']['body'] ?? ''}",
                  id: 1);
            }
          } else if (Platform.isAndroid) {
            notiType = message['data']['Notificationtype'];

            print('Android on message /*${message['data']['body']}*/');
            if (type == "0") {
              reloadData(type, message);
            } else {
              showSilentNotification(flutterLocalNotificationsPlugin,
                  title:
                      "${message['data']['title'] ?? message['notification']['title'] ?? ''}",
                  payload: "${message['data']['Notificationtype'] ?? ''}",
                  body:
                      "${message['data']['body'] ?? message['notification']['body'] ?? ''}",
                  id: 1);
            }
          }
        }
like image 329
BigPictureDeepDive Avatar asked Mar 12 '21 06:03

BigPictureDeepDive


1 Answers

Start from version 8.0.0-dev.1, configure() has been removed in favor of calling specific static methods which return Streams.

You should use FirebaseMessaging.onMessage(),FirebaseMessaging.onMessageOpenedApp() instead.

Here the example

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
        ...
});

You can find more on this pub's changelog.

like image 57
John Joe Avatar answered Oct 03 '22 08:10

John Joe