19

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
Saeid
  • 2,261
  • 4
  • 27
  • 59
  • I have this problem as well. I wonder, do you use Firebase for anything in this app? – Kirby Jan 05 '19 at 21:34
  • No @Kirby, just simple `http connection`, I really do have any idea why this is happens, it happens for you on all devices or just on iOS? – Saeid Jan 06 '19 at 12:09
  • This error is always happening to me on Samsung Galaxy S10 (API 10) Genimotion's emulator. – SalahAdDin Sep 08 '21 at 09:26

13 Answers13

6

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

Osman
  • 1,496
  • 18
  • 22
3

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

dhanasekar
  • 1,228
  • 13
  • 16
2

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

dilip
  • 163
  • 8
2

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

blurfus
  • 13,485
  • 8
  • 55
  • 61
sempernoob
  • 186
  • 2
  • 8
1

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

Sreekuttan
  • 1,579
  • 13
  • 19
1

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

Pushkara Sharma
  • 101
  • 1
  • 2
1

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.

Axes Grinds
  • 756
  • 12
  • 24
0

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

Ray Zion
  • 610
  • 10
  • 11
0

restarting my phone helped me.

Mosayeb Masoumi
  • 481
  • 4
  • 10
0

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.

shaderone
  • 408
  • 9
  • 21
-1

just upgrade u'r flutter this is work for me

Dwi Nur Rohman
  • 425
  • 2
  • 5
  • 13
-1

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.

AMS Abu
  • 89
  • 1
  • 1
-1

I was also getting same error and i did the following and it resolved my issue:

  1. Restart your phone/emulator
  2. Reconnect your Device/emulator with your IDE and restart as well your IDE
loopassembly
  • 2,653
  • 1
  • 15
  • 22