setCustomCodeActionHandler method

void setCustomCodeActionHandler(
  1. CustomCodeActionHandler handler
)

Set a handler for custom code actions

When a user clicks a button with a custom code action (JS type), your handler will be called with the custom code string.

Example:

PPGInAppMessages.instance.setCustomCodeActionHandler((code) {
  if (code == 'navigate_to_shop') {
    Navigator.pushNamed(context, '/shop');
  } else if (code == 'apply_discount') {
    applyDiscount();
  }
});

Implementation

void setCustomCodeActionHandler(CustomCodeActionHandler handler) {
  _customCodeHandler = handler;
  _setupEventListening();

  // Notify native side that we want to receive events
  InAppMessagesChannel.invokeMethod(
    method: InAppMethod.setCustomCodeActionHandler,
    arguments: {'enabled': true},
  ).catchError((e) {
    log('PPGInAppMessages: setCustomCodeActionHandler failed - $e');
  });
}