未处理的异常,将来的动态不是Future或List Books类型的子类型

问题描述 投票:1回答:1

如何将Future<dynamic>的数据传递到Future<List<dynamic>>

getall(BuildContext context, String url, String type) async {
  final response = await http.get(url, headers: { 
 'Accept': 'application/json' 'Authorization': 'Bearer $token'
  });
if (response.statusCode == 200) {
  switch(type){
  case "Chapters":
            List responseJson = json.decode(response.body)['data'];
            return responseJson.map((m) => new Subjects.fromJson(m)).toList();
            break;
   case "Subjects":
            List responseJson = json.decode(response.body)['data'];
            return responseJson.map((m) => new Chapters.fromJson(m)).toList();
            break; 
 } 
}
}

这是我想从getall获取数据的功能:

Future<List<Subjects>> getsubjects(BuildContext context, String url, String type) async {
  return getall(context, url, type);

Future<List<Chapters>> getchapters(BuildContext context, String url, String type) async {
  return getall(context, url, type);
}
asynchronous flutter dart
1个回答
0
投票
指定getall函数的返回类型应解决此问题。
© www.soinside.com 2019 - 2024. All rights reserved.