Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 714
Saeid Avatar asked Dec 26 '18 14:12

Saeid


4 Answers

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

like image 56
Osman Avatar answered Oct 06 '22 13:10

Osman


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

like image 29
dhanasekar Avatar answered Oct 06 '22 15:10

dhanasekar


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

like image 2
dilip Avatar answered Oct 06 '22 13:10

dilip


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

like image 1
Sreekuttan Avatar answered Oct 06 '22 15:10

Sreekuttan