i want to replace assets/1.json to api URL because the required data is in API not local, and how do i change it, i have tried but still getting error. Thank you
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;
}
CodePudding user response:
I don't know your API or it's response, but you probably want to pass response.body
to your jsonDecode
.