0

I keep getting 'Bad file descriptor' errors for Flutter on iOS production builds. According to Sentry, they come from the post request I am sending to the backend.

Code of post function:

            static Future<dynamic> post(
String endPoint, {
Map<String, dynamic>? body,
 }) async {
var uri = Uri.parse(_apiUrl + endPoint);
print('post: $uri');
print('body: $body');

http.Response response;

response = await http.post(
  uri,
  body: json.encode(body),
  headers: {
    'Content-type': 'application/json',
  },
);

// Check response: throws exception if not successful
_checkResponse(response);

return json.decode(response.body);
 }

 static void _checkResponse(http.Response res) {
print('_checkResponse code: ${res.statusCode}');

if (res.statusCode != 200) {
  var body = json.decode(res.body);
  print('body of error is : ${body['error']}');
  throw NetworkException(
    ExceptionError.fromMap(body['error']),
    statusCode: res.statusCode,
  );
}

}

Abdelrahman
  • 623
  • 7
  • 13
  • https://stackoverflow.com/questions/69862903/ios-14-gives-os-error-bad-file-descriptor-errno-9-when-doing-local-network – Ozan Taskiran Dec 14 '22 at 16:28
  • @targiasld my app doesn't support sharing data between same devices on a network. I am using the normal POST/GET requests only. Do I still need to do it? – Abdelrahman Dec 20 '22 at 20:31
  • There is an opened issue for the http dart https://github.com/dart-lang/http/issues/197 It is not unexpected for sockets to be invalidated when the app is suspended. From Apple's Documentation: If you do leave your data socket open when going into the background, you must correctly handle errors on that socket. – Mircea Dragota Apr 25 '23 at 08:00

0 Answers0