US Office

1176 Shadeville Rd, Crawfordville Florida 32327, USA

 +1 (850) 780-1313

India Office

Office No 405, Kabir Shilp, Opp. Kansar Hotel, Opp. Landmark, Kudasan, Gandhinagar, Gujarat 382421

[email protected]

How to Check Whether there is an Internet connection available on Flutter app?

Check Internet is Available or Not Flutter

How to Check Whether there is an Internet connection available on Flutter app?

While Using a Flutter Mobile Application you may have seen that some mobile application doesn’t have access to some functionality without the Internet. In that case, users require to Check Whether there is an Internet connection available or not? So we will go through the same within this article.

How to Check Whether there is an Internet Connection available on the Flutter App?

The connectivity plugin states in its docs that it only provides information if there is a network connection, but not if the network is connected to the Internet.

Add Dependency to pubspec.yaml like below:

dependencies:
  connectivity: ^0.4.2

Then users need to import the package below:

import 'dart:io';
try {
  final result = await InternetAddress.lookup('google.com');
  if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
    print('connected');
  }
} on SocketException catch (_) {
  print('not connected');
}

Users can also try the below method:

import 'package:connectivity/connectivity.dart';
Future<bool> check() async {
  var connectivityResult = await (Connectivity().checkConnectivity());
  if (connectivityResult == ConnectivityResult.mobile) {
    return true;
  } else if (connectivityResult == ConnectivityResult.wifi) {
    return true;
  }
  return false;
}

Conclusion:

So in this article, We have been through How to check whether there is an Internet Connection available on the Flutter app.

Thanks for Reading!!!
Keep Fluttering.

Do let us know if you need any assistance with Flutter? we’d love to assist you:)

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.

FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Comments
  • February 15, 2021
    Tim Kariuki

    Correct me if I am wrong… The connectivity plugin only determines if you are connected to the network via wifi or mobile. You may be connected to either with no internet connection. Right?

    reply
Post a Comment