from static method

WidgetAction from(
  1. WidgetView target,
  2. String eventName,
  3. View view,
  4. Map<String, API> apis,
  5. YamlMap map,
)

Implementation

static WidgetAction from(WidgetView target, String eventName, View view,
    Map<String, API> apis, YamlMap map) {
  Event? event;
  try {
    Event.values.forEach((e) {
      if (e.toString() == 'Event.' + eventName.toLowerCase()) {
        event = e;
      }
    });
  } catch (e) {
    throw Exception("Event by name=" + eventName + " is not supported");
  }
  WidgetAction? action;
  map.forEach((k, v) {
    if (k == "call") {
      APIHandler handler = APIHandler.from(view, apis, v);
      action = WidgetAction(target, event!, view, handler);
      if (event == Event.click) {
        final Widget orig = target.widget;
        target.widget = GestureDetector(
            onTap: () {
              print('ontap on ' + orig.key.toString());
              handler.handle(action!);
            },
            child: AbsorbPointer(child: orig));
      }
    } else {
      throw Exception('no handler found for event ' + event.toString());
    }
  });
  return action!;
}