CachedHttpResponse.fromMap constructor
CachedHttpResponse.fromMap(
- Map map
Constructs a CachedHttpResponse from a serialized map (e.g. from Hive).
Implementation
factory CachedHttpResponse.fromMap(Map<dynamic, dynamic> map) {
final rawBytes = map['bytes'];
final Uint8List bytes;
if (rawBytes is Uint8List) {
bytes = rawBytes;
} else if (rawBytes is List) {
bytes = Uint8List.fromList(List<int>.from(rawBytes));
} else {
bytes = Uint8List(0);
}
final rawHeaders = map['headers'];
final headers = <String, String>{};
if (rawHeaders is Map) {
rawHeaders.forEach((k, v) {
headers[k.toString()] = v.toString();
});
}
return CachedHttpResponse(
bytes: bytes,
statusCode: (map['statusCode'] as num?)?.toInt() ?? 200,
headers: headers,
createdAt: DateTime.fromMillisecondsSinceEpoch(
(map['createdAt'] as num?)?.toInt() ?? 0,
),
);
}