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.