skip to Main Content

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.

enter image description here

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;
  }

3

Answers


  1. 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);
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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',
                  },
    
            );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search