i want to call data api based on the selected parameters, but i'm having a bit of trouble and this has been going on for a few days and it's still not done.
this is the api you want to fetch data from. and also I marked the parameters.
and this is when i try to call data api
static Future<Map<String, DataKuliahModel>> getDataKuliah(int smt) async {
String url = Constant.baseURL;
String token = await UtilSharedPreferences.getToken();
await Future.delayed(const Duration(milliseconds: 1000));
// 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',
},
);
print(response.statusCode);
print(response.body);
final result = jsonDecode(response.body)['data'] as Map<String, dynamic>;
result.forEach((key, value) {
DataKuliahModel dataKuliah = DataKuliahModel.fromMap(value);
finalResult.addAll({
key: dataKuliah,
});
});
return finalResult;
}
CodePudding user response:
add body to
Uri.parse(
'$url/auth/mhs_siakad/perwalian/get_paket',
),
headers: {
'Authorization': 'Bearer $token',
},
body: {'smt':'7'}
or something like that:
var url = Uri.https('www.googleapis.com', '/books/v1/volumes', {'q': '{http}'});
var response = await http.get(url);
CodePudding user response:
make the the url like this
Uri.parse(
'$url/auth/mhs_siakad/perwalian/get_paket?smt=$smt',
)
i hope this will work for you, if not then let me know
CodePudding user response:
TRY this works
_getData(var smtId){
final response = await http.get(
Uri.parse(
'$url/auth/mhs_siakad/perwalian/get_paket?smt=$smtId',
),
headers: {
'Authorization': 'Bearer $token',
},
);
}