I have a screen with segmented bar and under each tab the data is shown by making two api calls
when I switch the tabs continuously without giving the api call to complete it shows an error
I/flutter (28873): Connection closed before full header was received
and it stops showing data but after a while it gets the data own its own
This happens when I switch screens as well
I want to avoid this error I have no clue how to Please help!!!
This is the network call that i am making
dashboard() async {
var coor= latitude.toString()+","+longitude.toString();
print("COORR"+coor.toString());
bool trustSelfSigned = true;
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => trustSelfSigned);
IOClient ioClient = new IOClient(httpClient);
String request_type = "get-top-vendor-list";
String user_id = widget.userid;
String coordinates=_center.toString();
TopVendors dashboard = new TopVendors();
dashboard.request_type = request_type;
dashboard.user_id = user_id;
dashboard.coordinates=coor.toString();
print("Now JSON string is ${dashboard.toMap()}");
var jsonString = json.jsonEncode(dashboard.toMap());
print("JSON String is $jsonString");
var map = await ioClient.post(UrlConstants.one,
headers: {
HttpHeaders.contentTypeHeader: "application/json",
'Accept': 'application/json',
},
body: jsonString);
print("After server call");
print(map.body);
String res = map.body;
ioClient.close();
var parsedJson = json.jsonDecode(res);
print("response"+res);
print("Parsed JSON is " + parsedJson.toString());
var toppicks = VendorRes.vendors(parsedJson['vendor_list']);
print("top picks" + toppicks.toString());
return toppicks;
}
question from:
https://stackoverflow.com/questions/65840715/post-api-call-hangs-while-getting-data 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…