我使用dio,改装来管理api连接。生成与注释和build_runner相关的代码。
我的问题是:我收到回复中的数据列表。生成的代码与我需要的代码不同。生成的代码中有一节包含此文本。
final _result = await _dio.fetch<Map<String, dynamic>>(_setStreamType<我需要的代码是这样的。
final _result = await _dio.fetch<List<dynamic>>(_setStreamType<示例我收到的答复:
[
{
'key1':'value1',
'key2':'value2',
'key3':'value3'
}
]发布于 2022-08-31 05:35:39
我解决了问题。
提供给http响应的数据类型必须为列表类型。因此,您的音频响应是List<dynamic>。
否则,响应生成器将返回Map类型。
这是我的代码片段:
@RestApi(baseUrl: BuildConfig.SERVER)
abstract class GetApiService {
factory GetApiService(Dio dio,{String baseUrl}) = _GetApiService;
@GET(MainApi.baseData)
@FormUrlEncoded()
Future<HttpResponse<List<ResponseItem>>> getDashboardHomeResponse(); ///Pay attention to the type , Type is List!
}https://stackoverflow.com/questions/73540657
复制相似问题