decodeStyletEvent function

  1. @visibleForTesting
StyletEvent decodeStyletEvent(
  1. Object? value
)

Decodes one platform-channel map into its strongly typed event.

Implementation

@visibleForTesting
StyletEvent decodeStyletEvent(Object? value) {
  final Map<Object?, Object?> map = _requiredMap(value, context: 'event');
  return switch (_requiredString(map, 'type')) {
    'motion' => _decodeMotionEvent(map),
    'prediction' => _decodePredictionEvent(map),
    'correction' => _decodeCorrectionEvent(map),
    'action' => _decodeActionEvent(map),
    'device' => _decodeDeviceEvent(map),
    'pad' => _decodePadEvent(map),
    'batch' => throw const FormatException(
      'Use decodeStyletEvents to decode a Stylet batch.',
    ),
    final String type => throw FormatException(
      'Unknown Stylet event type "$type".',
    ),
  };
}