Changed api for getting assets to return and request correct type
This commit is contained in:
parent
1160306117
commit
72e0682c38
2 changed files with 20 additions and 6 deletions
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
|
|
@ -391,9 +392,9 @@ class DefaultApi {
|
|||
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
|
||||
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
|
||||
///
|
||||
/// Returns a [Future] containing a [Response] with a [JsonObject] as data
|
||||
/// Returns a [Future] containing a [Response] with a [Uint8List] as data
|
||||
/// Throws [DioError] if API call or serialization fails
|
||||
Future<Response<dynamic>> getAsset({
|
||||
Future<Response<Uint8List>> getAsset({
|
||||
required String fid,
|
||||
CancelToken? cancelToken,
|
||||
ValidateStatus? validateStatus,
|
||||
|
|
@ -404,9 +405,10 @@ class DefaultApi {
|
|||
final _options = Options(
|
||||
method: 'GET',
|
||||
validateStatus: validateStatus,
|
||||
responseType: ResponseType.bytes,
|
||||
);
|
||||
|
||||
final _response = await _dio.request<dynamic>(
|
||||
final _response = await _dio.request<List<int>>(
|
||||
_path,
|
||||
options: _options,
|
||||
cancelToken: cancelToken,
|
||||
|
|
@ -414,8 +416,20 @@ class DefaultApi {
|
|||
onReceiveProgress: onReceiveProgress,
|
||||
);
|
||||
|
||||
return Response<dynamic>(
|
||||
data: _response,
|
||||
final respData = _response.data;
|
||||
if (respData == null) {
|
||||
throw DioError(
|
||||
requestOptions: _options.compose(
|
||||
_dio.options,
|
||||
_path,
|
||||
),
|
||||
type: DioErrorType.unknown,
|
||||
error: 'Response was null',
|
||||
);
|
||||
}
|
||||
|
||||
return Response<Uint8List>(
|
||||
data: Uint8List.fromList(respData),
|
||||
headers: _response.headers,
|
||||
isRedirect: _response.isRedirect,
|
||||
requestOptions: _response.requestOptions,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue