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

Saeid picture Saeid · Dec 26, 2018 · Viewed 11.7k times · Source

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

Answer

Osman picture Osman · Mar 2, 2019

Just reconnect your Device with your IDE and restart as well your IDE, after this it will work.