How to Check Internet Connection on Flutter app

Solved Flutter Errors

I have a network call to be executed. But before doing that I need to check whether the device have internet connectivity.

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.

Use this code:

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

Also Read:

https://coderog.com/how-to-give-internet-access-to-android-application/
Tags

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

Related articles

Contact us

Partner with Us for Comprehensive IT

We’re happy to answer any questions you may have and help you determine which of our services best fit your needs.

Your benefits:
What happens next?
1

We Schedule a call at your convenience 

2

We do a discovery and consulting meting 

3

We prepare a proposal 

Schedule a Free Consultation