Im trying to request JSONs and some images. The JSONs come just fine, as they are small. When im requesting images, I just get the following SocketException 95% of the time:
I/flutter ( 9249): Exception: type '(HttpException) => Null' is not a subtype of type '(dynamic) => dynamic'!!
On the server side it always appears with the status code 200. Sometimes the image does come threw and it works fine, but thats a rare event. This is the code for the request that is not working:
static Future<Uint8List> productImage(int imageID) async {
String basicAuth =
'Basic ' + base64Encode(utf8.encode("${Request.token}:"));
http.Response response;
http.Client client = http.Client();
try {
response = await client.get(
Uri.encodeFull("$serverURL/inStoreProduct/getProductImage/$imageID"),
headers: <String, String>{'Authorization': basicAuth},
);
} catch (SocketException) {
print(
"Exception: ${SocketException.toString()}!! Route: $serverURL/inStoreProduct/getProductImage/$imageID");
return null;
}
print(
"Route: $serverURL/inStoreProduct/getProductImage/$imageID -> ${response.statusCode}");
if (response.statusCode != 200) return null;
return response.bodyBytes;
}
I've tried everything, I have another project that works just fine and everything is exactly the same. Any idea why the connection is beeing broken?
Edit:
here's the function call :
var imgBytes = await InStoreRequests.productImage(imageID);