getBody<T> method
Returns the response body as TResult.
If the response body data cannot be converted to TResult, this
will throw an ApiException.
Since body data is streamed, it can only be received once. A call to one of the following methods / getters will drain the body stream:
Also throwOnError will drain the stream to parse error data in the case of a non-success status code.
Implementation
Future<T> getBody<T>() async {
if (T == String) {
return await getTextBody() as T;
} else if (T == Map<String, dynamic>) {
return await getJsonBody() as T;
} else if (T == Uint8List) {
return await getByteBody() as T;
} else if (T == List<dynamic>) {
return await getJsonListBody() as T;
} else if (T == Stream<Uint8List>) {
return bodyData.asUint8List() as T;
} else if (T == Stream<List<int>>) {
return bodyData as T;
} else if (T == dynamic) {
return jsonDecode(await getTextBody());
} else if (TypeCheck<void>().isSubtypeOf<T>()) {
return null as T;
}
throw ApiError.invalidType(T);
}