Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the responseType in the dio api call using retrofit in flutter?

I am trying to set the response type in one of an API call to bytes, but in retrofit I am not finding any option to set the response type.

I am using dio as http client.

  @GET(API.blah_blah)
  // I want to set the response Type I want to get, instead of json I need bytes
  Future<dynamic> getSomething();

something like this in the generated file.

   final _result = await _dio.request('some api url',
    queryParameters: queryParameters,
    options: RequestOptions(
        method: 'GET',
         // responseType: ResponseType.bytes,// this I have manually added
        extra: _extra,
        baseUrl: baseUrl),
    data: _data);
like image 784
meditat Avatar asked Oct 13 '25 10:10

meditat


1 Answers

Try this:

@GET(API.blah_blah)   
@DioResponseType(ResponseType.bytes)  
Future<HttpResponse<List<int\>>> getSomething();
like image 158
makaron Avatar answered Oct 15 '25 00:10

makaron