Ad

How To Check If Wi-fi Has Internet In The Flutter App

- 1 answer

How to check if connected wi-fi network has internet in the flutter app, when I use connectivityResult == ConnectivityResult.wifi from connectivity 3.0.6 package, it returns true, but the upcoming functionalities won't work if I disabled the wi-fi data connection.

Ad

Answer

You can check the connection to a web page to make sure you have an internet connection, something like this :

  checkConnection() async {
    try {
      final result = await InternetAddress.lookup('google.com');
      if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
        setState(() {
          con = true;
        });
      }
    } on SocketException catch (_) {
      setState(() {
        con = false;
      });
    }
  }

that's work for me good luck.

Ad
source: stackoverflow.com
Ad