Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check condition for `No Internet Connection' #827

Closed
1 task done
rrifafauzikomara opened this issue Jun 15, 2020 · 13 comments
Closed
1 task done

How to check condition for `No Internet Connection' #827

rrifafauzikomara opened this issue Jun 15, 2020 · 13 comments

Comments

@rrifafauzikomara
Copy link

rrifafauzikomara commented Jun 15, 2020

New Issue Checklist

  • I have searched for a similar issue in the project and found none

Issue Description and Steps

How to check condition for No Internet Connection using DioErrorType?
The test case, when I turn off the wifi and mobile data.

Code

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?

@jaydangar
Copy link

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.

@rrifafauzikomara
Copy link
Author

rrifafauzikomara commented Jun 18, 2020

@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.

@jaydangar
Copy link

There's another package called data_connection_checker which involved the exact thing we want.

@stale
Copy link

stale bot commented Jul 19, 2020

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.

@stale stale bot added the stale label Jul 19, 2020
@stale stale bot closed this as completed Jul 26, 2020
@ventr1x
Copy link

ventr1x commented Oct 27, 2020

How is this automatically closed?
This is a major issue, especially for file uploads.

No connection results in the most unwanted behaviour possible:

  • Dio "uploads" the entire file and actually updates the progress as if it is being uploaded (weird using UDP-style with no checks here, never ever seen that anywhere)
  • Dio does not detect that there is in fact no connection
  • Dio only reacts after the set overall timeout with an error

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.

@demetrio812
Copy link

Hello, any news on this issue? I agree this is a major issue, it's making me rethink about using Dio in my app

Thanks

@CARocha
Copy link

CARocha commented Mar 9, 2021

@demetrio812 yes this is a big problem i now i'm suffering and all my app writen wit Dio :/ i think change por http :/

@rrifafauzikomara
Copy link
Author

Any progress?

@jorgoncalves
Copy link

@demetrio812 yes this is a big problem i now i'm suffering and all my app writen wit Dio :/ i think change por http :/

I'm also rethinking the use of Dio. I use it with Retrofit and not being able to handle the loss of internet, mid request or not, is making it hard to keep on using it.

@wandriputra
Copy link

Still no update for this issue?

@jgoyvaerts
Copy link
Contributor

How is this automatically closed? This is a major issue, especially for file uploads.

No connection results in the most unwanted behaviour possible:

  • Dio "uploads" the entire file and actually updates the progress as if it is being uploaded (weird using UDP-style with no checks here, never ever seen that anywhere)
  • Dio does not detect that there is in fact no connection
  • Dio only reacts after the set overall timeout with an error

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.

Thanks for the feedback!

Since Dio is an open source project, we of course accept contributions in this area.

If you feel like the current implementation is lacking, feel free to create a pull request to improve it!

@ghost
Copy link

ghost commented Sep 6, 2023

will this issue ever be resolved? I am suffering from this issue as well even on latest dio: ^5.3.2

@kuhnroyal
Copy link
Member

If you think this needs improvement, please open a new ticket with a reproducible test case. But I don't think there is much dio can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants