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:
Just reconnect your Device with your IDE and restart as well your IDE, after this it will work.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With