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

331

Try this:

@GET(API.blah_blah)   
@DioResponseType(ResponseType.bytes)  
Future<HttpResponse<List<int\>>> getSomething();
Share:
331
meditat
Author by

meditat

Flutter Developer | Front-end Web Developer | Android App Developer | UI Designer Github Linkedin

Updated on December 06, 2022

Comments

  • meditat
    meditat over 1 year

    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);