IProovEvent.fromMap constructor

IProovEvent.fromMap(
  1. Map map
)

Implementation

factory IProovEvent.fromMap(Map map) {
  switch (map['event']) {
    case 'connecting':
      return const IProovEventConnecting();

    case 'connected':
      return const IProovEventConnected();

    case 'processing':
      return IProovEventProcessing(map['progress'], map['message']);

    case 'success':
      final frameData = map['frame'];
      final frame = frameData != null ? decodePng(frameData) : null;
      return IProovEventSuccess(frame);

    case 'failure':
      final frameData = map['frame'];
      final frame = frameData != null ? decodePng(frameData) : null;
      return IProovEventFailure(map['reason'], map['feedbackCode'], frame);

    case 'canceled':
      final canceler = map['canceler'];
      return IProovEventCanceled(Canceler.values.byName(canceler));

    case 'error':
      return IProovEventError.create(map['error'], map['title'], map['message']);
  }
  throw Exception('Invalid event');
}