如何使用flutter中的retrofit在dio api调用中设置responseType?

med*_*tat 4 retrofit flutter dio

我正在尝试在对 的 API 调用之一中设置响应类型bytes,但在改造中我没有找到任何设置响应类型的选项。

我使用 dio 作为 http 客户端。

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

生成的文件中类似这样的内容。

   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);
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试这个:

@GET(API.blah_blah)   
@DioResponseType(ResponseType.bytes)  
Future<HttpResponse<List<int\>>> getSomething();
Run Code Online (Sandbox Code Playgroud)