D
NetworkingEasy20 XP3 min read

How do you check and monitor internet connectivity in Flutter?

TL;DR: Use the connectivity_plus package to listen to ConnectivityResult changes (wifi, mobile, none). Note: a ConnectivityResult.wifi result doesn't guarantee internet — always do an actual HTTP request or socket check to confirm.

Full Answer

connectivity_plus checks the network interface status, not actual internet reachability. A device on a captive portal (hotel WiFi) shows ConnectivityResult.wifi but has no real internet.

True Reachability Check

To check real internet access, make a lightweight HTTP request (e.g., HEAD to 1.1.1.1 or your own health endpoint) and catch connection errors.

⚠️

Never gate your UI solely on ConnectivityResult — it lies on captive portals. Always handle network errors at the request level.

Code Examples

dartMonitoring connectivity changes
Output
// Banner appears when network interface drops
// hasInternet() does DNS lookup for true reachability

Common Mistakes

  • Assuming ConnectivityResult != none means real internet is available
  • Checking connectivity on every API call instead of handling network errors at the Dio level

Interview Tip

💡

Show you know the difference between network interface check (connectivity_plus) vs true reachability (DNS/socket check). It's a common gotcha.

#connectivity#internet-check#connectivity_plus