ForegroundDownloadEvent.fromMap constructor

ForegroundDownloadEvent.fromMap(
  1. Map<Object?, Object?> map
)

Implementation

factory ForegroundDownloadEvent.fromMap(Map<Object?, Object?> map) {
  final downloadedBytes = (map['downloadedBytes'] as num?)?.toInt() ?? 0;
  final totalBytes = (map['totalBytes'] as num?)?.toInt() ?? 0;
  return ForegroundDownloadEvent(
    type: ForegroundDownloadEventType.parse(map['type'] as String?),
    state: ForegroundDownloadState.parse(map['state'] as String?),
    sessionId: (map['sessionId'] as num?)?.toInt(),
    savePath: map['savePath'] as String?,
    downloadedBytes: downloadedBytes,
    totalBytes: totalBytes,
    progress: totalBytes > 0
        ? (downloadedBytes / totalBytes).clamp(0.0, 1.0)
        : null,
    code: map['code'] as String?,
    message: map['message'] as String?,
    networkRetryCount: (map['networkRetryCount'] as num?)?.toInt() ?? 0,
    validationRetryCount: (map['validationRetryCount'] as num?)?.toInt() ?? 0,
  );
}