简体   繁体   中英

Flutter occurs 'Error connecting to the service protocol: HttpException...' error on iOS device

For.network connection I use dio and for checking connection state from Connectivity .

And in here I check.network state:

@override
 Widget build(BuildContext context) {

 bloc.checkConnectivity(Connectivity());

 return StreamBuilder(
    stream: bloc.getInitApp,
    builder: (context, AsyncSnapshot<InitApp> initApp) {
      if (initApp.hasData) {
        return prepareMain(initApp.data);
      } else {
        return Center(
          child: CircularProgressIndicator(),
        );
      }
    });
}

checkConnectivity method:

checkConnectivity(Connectivity _connectivity) {
 _connectivity.onConnectivityChanged.listen((ConnectivityResult result){
   if (result == ConnectivityResult.mobile ||
       result == ConnectivityResult.wifi) {
       fetchInitApp();
    }
   });
 }

But eventually, App runs just on Android device but on iOS(Device/Simulator) occurs this error:

Error connecting to the service protocol: HttpException: , uri = http://127.0.0.1:1024/ws

I tried to call Api without Connectivity and the app work as good but with it gets data just in Android and for iOS still there is problem.

Too, it happens with Dart http package.


Edit 1: 25 Sep 2019

This has nothing to do with codes!

The problem is the system WiFi connection.

When you faced with this problem use this temporary solution until a complete solution is provided:

  1. Disconnect system WiFi
  2. Unplug your phone
  3. Reconnect your system to WiFi
  4. Plug your phone
  5. Run the application

只需将您的设备与您的 IDE 重新连接并重新启动您的 IDE,此后它将工作。

run flutter clean command- it deletes the previous build. then execute try flutter run command

I have the same issue. When it happens, I unplug/plug the iPhone and it starts working.

If you are sharing network from your mac, disable it. it's worked for me.

Use Android API 28 instead of API 29.

That worked for me.

The same issue came across me and I'm using an android studio in windows. The issue was in flutter_facebook_login dependency(using firebase) that I want to use for FB login. The version of this dependency was 3.0.0, So finally I removed this dependency and everything worked fine

Looks like the Facebook plugin is causing this issue . If you are using it, try disabling it.

Any sufficiently old plugin can cause this issue. If you really need the plugin and is has not been recently updated then you can add the folder locally to your project and upgrade the gradle build files. But that's only if you can't find an alternative recently updated plugin. Facebook login plugin fixed this issue in a recent update so the newest facebook login plugins no longer have this fault. As for me, I had to check each of my packages one by one to see which one was causing the issue. This involved opening a new android studio project and only adding the flutter packages and no other code then run the app with adding the plugins 1 by 1 until you find which plugin is at fault. A faster way would be to check each plugin on pub.dev and see which one hasn't been updated in recent months and is using older gradle files.

The cause was for me a non-null safe plugin:

1.) So I copied it to lib folder

2.)and made it null safe

3.)then removed it from pubspec.yaml

我也遇到了同样的错误,我只做了一件事,它解决了我的问题

Restart your phone/emulator

restarting my phone helped me.

If you close your application from the device itself when it is running, you'll get this error the next time you run. [Tested this 3 times & i'm using a physical device - SM J111F(samsung galaxy duos)-android-arm] another cause would be one or more of the plugins that you use

The only thing that worked is to Reload the IDE(vs-code) before running again or restart the physical device .

Earlier i tried many commands and workarounds..flutter clean..flutter pub get, adb kill-server...adb usb...modifying pubspec but nothing worked out for me.

只需升级你的颤振,这对我有用

I had similar issue, but only started when I wanted to run the app from the IDE which was running fine from the terminal. Somehow, the error only occurs when I want to run the app from the terminal and the IDE interchangeably. WHAT WORKED FOR ME... I restarted my connected device and ran the app from the terminal and it was fine again. However, the error returned once I wanted to run from the IDE. I restarted my connected device again and ran the app straight from the IDE this time and it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM