How to check condition for No Internet Connection using DioErrorType?
The test case, when I turn off the wifi and mobile data.
try {
yield MoviesLoading();
var movies = await repository.getNowPlaying(ApiConstant.apiKey, ApiConstant.language);
if (movies.results.isEmpty) {
yield MoviesNoData(AppConstant.noData);
} else {
yield MoviesHasData(movies);
}
} on DioError catch (e) {
if (e.type == DioErrorType.CONNECT_TIMEOUT || e.type == DioErrorType.RECEIVE_TIMEOUT) {
yield MoviesNoInternetConnection(AppConstant.noInternetConnection);
} else {
yield MoviesError(e.toString());
}
}
e.type == DioErrorType.CONNECT_TIMEOUT || e.type == DioErrorType.RECEIVE_TIMEOUT for handle Timeout, yield MoviesError(e.toString()); for handle Error from Dio. So how to handle No Internet Connection using DioError?
True this is the major problem dio is having, We can simply integrate Dio with connectivity package and before sending a request we can check for connection, if connection doesn't exists, then we can add a new DioError called NotConnectedException, which will give us the liberty to use it efficiently.
@jaydangar I don't recommend using connectivity package because If you are connected to wifi or mobile data but actually there is no internet data. The connectivity return true (has internet data). So I will not recommend it to check the internet connection. Because it's just to check the status not to check the internet connection.
There's another package called data_connection_checker which involved the exact thing we want.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
How is this automatically closed?
This is a major issue, especially for file uploads.
No connection results in the most unwanted behaviour possible:
This behaviour is basically valid for any request, it just throws an error faster with smaller payload or GET requests.
To me this makes this package unusable outside the most simplest requests.
And using more plugins to wrap this one with correct functionality should not be the goal.
Dio simply does not implement the http correctly. There are e.g. options/pre-flight requests for exactly this reason.
Most helpful comment
How is this automatically closed?
This is a major issue, especially for file uploads.
No connection results in the most unwanted behaviour possible:
This behaviour is basically valid for any request, it just throws an error faster with smaller payload or GET requests.
To me this makes this package unusable outside the most simplest requests.
And using more plugins to wrap this one with correct functionality should not be the goal.
Dio simply does not implement the http correctly. There are e.g. options/pre-flight requests for exactly this reason.