【发布时间】:2020-05-11 10:48:36
【问题描述】:
如何将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