toJson method

Map<String, dynamic> toJson()

Converts this event to a JSON-compatible map.

Implementation

Map<String, dynamic> toJson() {
  final event = <String, dynamic>{
    'EventType': type == HapticEventType.transient
        ? 'HapticTransient'
        : 'HapticContinuous',
    'Time': time,
    'EventParameters': [
      {
        'ParameterID': 'HapticIntensity',
        'ParameterValue': intensity,
      },
      {
        'ParameterID': 'HapticSharpness',
        'ParameterValue': sharpness,
      },
    ],
  };

  if (type == HapticEventType.continuous && duration != null) {
    event['EventDuration'] = duration!;
  }

  return event;
}