Vanethos / flutter_connectivity_widget

A widget that shows the user if the phone is connected to the internet or not
BSD 2-Clause "Simplified" License
68 stars 35 forks source link

Add option to provide custom server to ping #1

Closed MarcelGarus closed 5 years ago

MarcelGarus commented 5 years ago

As discussed in the comments of the accepted answer to this StackOverflow question, pinging Google is not a reliable factor to verify there's an internet connection.

I'm not saying that Google would ever have any downtime — but there are areas where internet traffic is restricted. Just imagine people living in China, for whom this widget doesn't work, because Google is blocked. Or students in schools, where the request fails because HTTPS is intercepted. Or companies where certain IPs are blocked and your server isn't reachable but Google's is, leading to strange behavior.

There is no "one internet" because the internet is a mess of interconnected devices, so to determine whether to display the connectivity message, an app should check whether its own server is reachable.

Vanethos commented 5 years ago

Hi @marcelgarus

Yes! Pinging google is not the best option, and that is why I offer the option to ping another server via

ConnectivityUtils.instance.setServerToPing("https://gist.githubusercontent.com/Vanethos/dccc4b4605fc5c5aa4b9153dacc7391c/raw/355ccc0e06d0f84fdbdc83f5b8106065539d9781/gistfile1.txt");

I use that in our project to ping a file in our server

Is this ok for you?

MarcelGarus commented 5 years ago

Yup 😄 To me, it seems like just adding an optional parameter to the widget would be a cleaner API surface but this will do the trick.