Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter: API Calls are so slow in flutter, taking more than 20s to load with WiFi and less than a sec with Mobile Data #112285

Closed
jerrypaulsam opened this issue Sep 23, 2022 · 4 comments
Labels
r: solved Issue is closed as solved

Comments

@jerrypaulsam
Copy link

jerrypaulsam commented Sep 23, 2022

I have a weird issue with Flutter (Android app only) for the past few days. I make 3 API calls, which usually takes less than 2 sec to load, but for the past few days it's taking more than 20s to load with WiFi and less than 2 sec with mobile data. I tried with multiple WiFi networks but the result is same. The problem exists with Android app only and works fine with iOS. Wifi connection speeds were more than 100Mbps.

With postman, the same calls can be made in 0.7s.

I use Dio for api calls.

Has anyone faced this issue? I'm not able to understand the reason. Help would be highly appreciated.

Thank you

**UPDATE - The same api calls works normally (loads fast) in android phones running Android 9 or less with WiFi.

This is flutter doctor -v

`[✓] Flutter (Channel stable, 3.3.2, on macOS 12.5.1 21G83 darwin-arm, locale en-IN)
• Flutter version 3.3.2 on channel stable at /Users/davin/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision e3c29ec00c (9 days ago), 2022-09-14 08:46:55 -0500
• Engine revision a4ff2c53d8
• Dart version 2.18.1
• DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/davin/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13F100
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.71.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • SM N975F (mobile)          • RF8M749NZ7J                          • android-arm64  • Android 12 (API 31)
    • iPhone 13 Pro Max (mobile) • 6B4691F0-AFA4-44E6-82BD-4E946DC60D45 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 12.5.1 21G83 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 105.0.5195.125

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!`
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Sep 26, 2022
@darshankawar
Copy link
Member

I use Dio for api calls.

@jerrypaulsam Can you try using http package and see using it, you get same behavior ?

See this for your reference and check if it helps in your case.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 26, 2022
@jerrypaulsam
Copy link
Author

I was able to solve this issue, it is related to ipv4 and ipv6 requests.

Somehow flutter android apps with android version greater than 10 is trying to connect to ipv6 address automatically and only after failing, reverting to ipv4, so there is a huge delay in getting response whereas in Android 9 and less, this isn't a problem. In flutter, there should be an option to manually choose ipv4 or ipv6 addresses.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 26, 2022
@darshankawar
Copy link
Member

Good to know that issue is resolved. Closing.

@darshankawar darshankawar added r: solved Issue is closed as solved and removed in triage Presently being triaged by the triage team labels Sep 26, 2022
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: solved Issue is closed as solved
Projects
None yet
Development

No branches or pull requests

2 participants