Search code examples
jsonflutterhttpdartget

Flutter send json body in Http GET Method


i tried many solutions but it still give me the same error :

"Unhandled Exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>?'"

 Future<GetCustomerList> _getStateList() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
var token = prefs.getString("userToken");
 final String url = "http://194.195.245.189:8069/get_partners?params: {}";
Map<dynamic, dynamic> qParams = {
  "params": {}
};
Map<String, String> headers = {'Cookie':'session_id=$token',
  'Content-Type':'application/json; charset=UTF-8'};
var customerList = await http.get(Uri.parse(url),headers: headers,body: qParams);
if (customerList.statusCode == 200) {
  return GetCustomerList.fromJson(json.decode(customerList.body));
} else {
  throw Exception('Failed to load Customers');
}

}


Solution

  • you have to convert your result into a map take inspiration from this link

    Unhandled Exception: InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>