UDownloadRequest.fromJson constructor

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

Reads it from JSON.

Implementation

factory UDownloadRequest.fromJson(Map<String, dynamic> json) => UDownloadRequest(
  url: json["url"] as String? ?? "",
  sourceId: json["sourceId"] as String?,
  mirrors: (json["mirrors"] as List<dynamic>?)?.cast<String>() ?? const <String>[],
  headers: (json["headers"] as Map<String, dynamic>?)?.map((String k, dynamic v) => MapEntry<String, String>(k, "$v")) ?? const <String, String>{},
  fileName: json["fileName"] as String?,
  title: json["title"] as String?,
  mimeType: json["mimeType"] as String?,
  destination: UDownloadDestination.fromJson(json["destination"] as Map<String, dynamic>),
  priority: UDownloadPriority.values.firstWhere((UDownloadPriority p) => p.name == json["priority"], orElse: () => UDownloadPriority.normal),
  connections: json["connections"] as int?,
  speedLimit: json["speedLimit"] as int? ?? 0,
  checksum: json["checksum"] == null ? null : UChecksum.fromJson(json["checksum"] as Map<String, dynamic>),
  wifiOnly: json["wifiOnly"] == true,
  startAt: json["startAt"] == null ? null : DateTime.fromMillisecondsSinceEpoch(json["startAt"] as int),
  conflict: UDownloadConflict.values.firstWhere((UDownloadConflict c) => c.name == json["conflict"], orElse: () => UDownloadConflict.rename),
  maxRetries: json["maxRetries"] as int? ?? 8,
  useSystemDownloader: json["system"] == true,
  openWhenDone: json["openWhenDone"] == true,
  notifyWhenDone: json["notifyWhenDone"] == true,
  visible: json["visible"] != false,
  expireIn: json["expireIn"] == null ? null : Duration(seconds: json["expireIn"] as int),
  tag: json["tag"] as String?,
  metadata: (json["metadata"] as Map<String, dynamic>?)?.map((String k, dynamic v) => MapEntry<String, String>(k, "$v")) ?? const <String, String>{},
);