onActionReceivedMethod static method

Future<void> onActionReceivedMethod(
  1. ReceivedAction receivedAction
)

Implementation

static Future<void> onActionReceivedMethod(
    ReceivedAction receivedAction) async {
  if (receivedAction.actionType == ActionType.SilentAction ||
      receivedAction.actionType == ActionType.SilentBackgroundAction) {
    // For background actions, you must hold the execution until the end
    if (kDebugMode) {
      print(
        'Message sent via notification input: "${receivedAction.buttonKeyInput}"');
    }
    await executeLongTaskInBackground();
  } else {
    // this process is only necessary when you need to redirect the user
    // to a new page or use a valid context, since parallel isolates do not
    // have valid context, so you need redirect the execution to main isolate
    if (receivePort == null) {
      if (kDebugMode) {
        print(
          'onActionReceivedMethod was called inside a parallel dart isolate.');
      }
      SendPort? sendPort =
          IsolateNameServer.lookupPortByName('notification_action_port');

      if (sendPort != null) {
        if (kDebugMode) {
          print('Redirecting the execution to main isolate process.');
        }
        sendPort.send(receivedAction);
        return;
      }
    }
    if (kDebugMode) {
      print("check data with receivedAction 3$receivedAction");
    }

    return onActionReceivedImplementationMethod(receivedAction);
  }
}