toResult<T> static method
Converts a list of bytes into a result of type T
.
Handles various types of conversions, including JSON decoding, byte lists, and casting to other types.
bytes
: The response body as a list of bytes.
Returns: The parsed response as an object of type T
.
Implementation
static T toResult<T>(List<int> bytes) {
if (bytes.isEmpty && null is T) {
return null as T;
}
if (dynamic is T) {
return StringUtils.toJson(StringUtils.decode(bytes));
}
if (<String, dynamic>{} is T) {
return StringUtils.toJson(StringUtils.decode(bytes));
}
if (<Map<String, dynamic>>[] is T) {
return StringUtils.toJson<List>(StringUtils.decode(bytes))
.map((e) => (e as Map).cast<String, dynamic>())
.toList() as T;
}
if (<int>[] is T) {
return bytes as T;
}
return StringUtils.decode(bytes) as T;
}