dispatchAction static method

Future<void> dispatchAction(
  1. Map<String, dynamic> model, {
  2. required String buttonKey,
  3. String? input,
  4. Map<String, dynamic>? button,
})

Emits the action event of model (a model map, as given to a builder), as a pressed button does: onActionReceivedMethod receives it.

Implementation

static Future<void> dispatchAction(
  Map<String, dynamic> model, {
  required String buttonKey,
  String? input,
  Map<String, dynamic>? button,
}) async {
  final handler = engine.actionHandler;
  if (handler == null) return;
  final content = Map<String, dynamic>.from(
      (model[NOTIFICATION_CONTENT] as Map?) ?? const {});
  final action = ReceivedAction().fromMap({
    ...content,
    NOTIFICATION_BUTTON_KEY_PRESSED: buttonKey,
    NOTIFICATION_BUTTON_KEY_INPUT: input ?? '',
    if (button?[NOTIFICATION_ACTION_TYPE] != null)
      NOTIFICATION_ACTION_TYPE: button![NOTIFICATION_ACTION_TYPE],
    NOTIFICATION_ACTION_LIFECYCLE: NotificationLifeCycle.Foreground.name,
    NOTIFICATION_ACTION_DATE:
        AwesomeDateUtils.parseDateToString(DateTime.now().toUtc()),
  });
  await handler(action);
}