'Network requests in Flutter app on physical iOS devices are slow

I am working on a cross-platform app using Flutter, for Android, iOS and Web. For some reason though, network requests on iOS are very slow.

The app works fine on Android and Web. The slow network requests don't seem to be due to performance issues; the UI works fast and I have sort of deduced (using a stopwatch) that the delay is always 10 seconds. The delay affects both HTTP (https://) and WebSocket (wss://) requests. Even more puzzling, the app runs fine on simulator devices. I have tried a variety of physical iOS devices but the result has been the same.

For context, I am using the Dart HTTP library (https://pub.dev/packages/http) for HTTP requests. Also, flutter --version gives

Flutter 2.6.0-6.0.pre.5 • channel master • https://github.com/flutter/flutter.git
Framework • revision 33755f203d (8 weeks ago) • 2021-09-05 13:16:01 -0700
Engine • revision dbc97a09b4
Tools • Dart 2.15.0 (build 2.15.0-82.0.dev)

Is this a known issue with Dart/Flutter? I am willing to provide specifics if needed for clarification.



Solution 1:[1]

Fixed this already so I'll post an answer in case anyone else has the same issue.

It turned out to be an IPv4 issue. I noticed that hosts with IPv6 support worked just fine, but my backend which used only IPv4 had this problem. Apparently, a Dart SDK issue was raised already and was fixed/resolved, but I still had the problem even after updating my installation (https://github.com/dart-lang/sdk/issues/41451#issuecomment-1003663129).

Switching to Cloudflare DNS and enabling IPv6 support solved the problem, although I presume it would still work with any other means of IPv6 support.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Victor Durojaiye