Skip to content

MissingPluginException when calling external plugin via firebase_messaging onBackgroundMessage #3029

Closed
@joshuakoh1

Description

@joshuakoh1

I'm trying to call a function from within firebase_messaging's onBackgroundMessage. The function works when called from the function registered to onMessage but throws plugin error from the function registered to onBackgroundMessage.

void sendTargetSMS(TargetSMS sms) async {
  SmsSender sender = new SmsSender();
  try {
    SimCardsProvider provider = new SimCardsProvider();
    List<SimCard> cards = await provider.getSimCards();
    ...
  } catch (error) {
    print(error.toString());
  }
}

This works with no errors when called from the onMessage function that is within the MyApp function

  Future notificationOnMessage(Map<String, dynamic> message) async {
    print('OnMessage');
    ...
    try {
      sendTargetSMS(sms);
    } catch (e) {
      print(e);
    }
  }

But when calling this same function from onBackgroundMessage function which exists outside of the main MyApp function

Future notificationOnBackground(Map<String, dynamic> message) async {
  print('OnBackground');
  ...
  try {
    sendTargetSMS(sms);
  } catch (e) {
    print(e);
  }
}

I get missing plugin exception

MissingPluginException(No implementation found for method getSimCards on channel plugins.babariviere.com/simCards)

Both of them are init via configureFirebase

  void configureFirebase(FirebaseMessaging _firebaseMessaging) {
    try {
      _firebaseMessaging.configure(
        onMessage: notificationOnMessage,
        onLaunch: notificationOnLaunch,
        onResume: notificationOnResume,
        onBackgroundMessage: notificationOnBackground,
      );
    } catch (e) {
      print('Error Config Firebase');
      print(e);
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions