HeadlessEvent constructor

HeadlessEvent(
  1. String name,
  2. dynamic params
)

Implementation

HeadlessEvent(String name, dynamic params) {
  this.name = name;

  try {
    switch (name) {
      case Event.TERMINATE:
      case Event.SCHEDULE:
      case Event.BOOT:
        event = new State(params);
        break;
      case Event.LOCATION:
        event = new Location(params);
        break;
      case Event.MOTIONCHANGE:
        event = new Location(params['location']);
        break;
      case Event.ACTIVITYCHANGE:
        event =
            new ActivityChangeEvent(params['activity'], params['confidence']);
        break;
      case Event.GEOFENCE:
        event = new GeofenceEvent(params);
        break;
      case Event.GEOFENCESCHANGE:
        event = new GeofencesChangeEvent(params['on'], params['off']);
        break;
      case Event.HEARTBEAT:
        event = new HeartbeatEvent(params);
        break;
      case Event.HTTP:
        event = new HttpEvent(params);
        break;
      case Event.PROVIDERCHANGE:
        event = new ProviderChangeEvent(params);
        break;
      case Event.CONNECTIVITYCHANGE:
        event = new ConnectivityChangeEvent(params['connected']);
        break;
      case Event.ENABLEDCHANGE:
        event = params;
        break;
      case Event.POWERSAVECHANGE:
        event = params;
        break;
      case Event.AUTHORIZATION:
        event = new AuthorizationEvent(params);
        break;
      case Event.NOTIFICATIONACTION:
        event = params;
        break;
    }
  } catch (e, stacktrace) {
    print('[HeadlessEvent] ‼️ ERROR DECODING EVENT $name: $e');
    print(params.toString());
    print(stacktrace);
  }
}