我想将assets/1.json替换为api URL,因为所需的数据在API中,而不是本地的,我该如何更改它,我已经尝试过了,但仍然出错。谢谢
static Future<Map<String, DataKuliahModel>> getDataKuliah() async {
String url = Constant.baseURL;
String token = await UtilSharedPreferences.getToken();
await Future.delayed(const Duration(seconds: 4));
// String responseJson = await rootBundle.loadString('assets/1.json');
Map<String, DataKuliahModel> finalResult = {};
final response = await http.get(
Uri.parse(
'$url/auth/mhs_siakad/perwalian/get_paket',
),
headers: {
'Authorization': 'Bearer $token',
},
);
final result = jsonDecode(response)['data'] as Map<String, dynamic>;
result.forEach((key, value) {
DataKuliahModel dataKuliah = DataKuliahModel.fromMap(value);
finalResult.addAll({
key: dataKuliah,
});
});
return finalResult;
}
1条答案
按热度按时间h22fl7wq1#
我不知道你的API或它的响应,但你可能想把
response.body
传递给你的jsonDecode
。