RegistrationEvent.fromMap constructor

RegistrationEvent.fromMap({
  1. required Map<Object?, Object?> event,
})

Factory method to translate dictionary to RegistrationEvent

Implementation

factory RegistrationEvent.fromMap({required Map<Object?, Object?> event}) {
  switch (event["event"] as String?) {
    case 'REGISTERED':
      return RegistrationRegisteredEvent();
    case 'REGISTERING':
      return RegistrationRegisteringEvent();
    case 'NOT_REGISTERED':
      return RegistrationNotRegisteredEvent();
    case 'OFFLINE':
      return RegistrationOfflineEvent();
    case 'NO_CONNECTION':
      return RegistrationNoConnectionEvent();
    case 'ERROR':
      final err = RegistrationError.fromString(event["error"] as String?);
      final msg = event["message"] as String?;
      return RegistrationErrorEvent(error: err, message: msg ?? "");
    default: // fall through
  }
  throw Exception("Unknown registration event: $event");
}