ObservationOptions.fromJson constructor

ObservationOptions.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory ObservationOptions.fromJson(Map<String, dynamic> json) {
  final detailName = json['detail']?.toString() ?? 'standard';
  final detail = ObservationDetailLevel.values.firstWhere(
    (v) => v.name == detailName,
    orElse: () => ObservationDetailLevel.standard,
  );
  final syncName = json['synchronization']?.toString() ?? 'untilStable';
  final sync = ObservationSynchronization.values.firstWhere(
    (v) => v.name == syncName,
    orElse: () => ObservationSynchronization.untilStable,
  );
  final timeoutMs = json['stableTimeoutMs'];
  return ObservationOptions(
    detail: detail,
    synchronization: sync,
    stableTimeout:
        timeoutMs is int ? Duration(milliseconds: timeoutMs) : null,
    includeScreenshot: json['includeScreenshot'] == true,
    includeBounds: json['includeBounds'] != false,
    allowPartial: json['allowPartial'] == true,
    keyedOnly: json['keyedOnly'] == true,
  );
}