AmountEstimate.fromJson constructor

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

Creates a AmountEstimate instance from a JSON map.

Implementation

factory AmountEstimate.fromJson(Map<String, dynamic> json) {
  // Extract estimationQuality from JSON and convert it to EstimationQuality enum
  EstimationQuality? estimationQuality = (json['estimationQuality'] != null)
      ? EstimationQuality.values.firstWhere(
          (element) => element.name == json['estimationQuality'],
          orElse: () => EstimationQuality.noEstimation)
      : null;

  // Extract moveDevice from JSON and convert it to MoveDirection enum
  MoveDirection? moveDevice = (json['moveDevice'] != null)
      ? MoveDirection.values.firstWhere(
          (element) => element.name == json['moveDevice'],
          orElse: () => MoveDirection.ok)
      : null;

  // Extract volumeEstimate, viewingAngle, and weightEstimate from JSON
  double? volumeEstimate = json["volumeEstimate"];
  double? viewingAngle = json["viewingAngle"];
  double? weightEstimate = json["weightEstimate"];

  // Create and return an AmountEstimate object with the extracted values
  return AmountEstimate(
    estimationQuality: estimationQuality,
    moveDevice: moveDevice,
    volumeEstimate: volumeEstimate,
    viewingAngle: viewingAngle,
    weightEstimate: weightEstimate,
  );
}